试图创建计算器以计算大小和输出结果的差异
这是脚本使用。
用于计算基准直径的脚本签出-https://code.sololearn.com/wahq9E8aL5I3
<script language="JavaScript" type="text/JavaScript">
function Calculate1 ( section1, profile1, diameter1 ) {
rollingradius1=Math.round((((diameter1/2)*25.4)+(section1*(profile1/100)))*100)/100;
circumference1=Math.round((rollingradius1*2*3.14159)*100)/100;
document.wheelsizes.rollingradius1.value=rollingradius1;
document.wheelsizes.circumference1.value=circumference1;
}
function Calculate2 ( section2, profile2, diameter2 ) {
rollingradius2=Math.round((((diameter2/2)*25.4)+(section2*(profile2/100)))*100)/100;
circumference2=Math.round((rollingradius2*2*3.14159)*100)/100;
document.wheelsizes.rollingradius2.value=rollingradius2;
document.wheelsizes.circumference2.value=circumference2;
}
function Difference ( circumference1, circumference2 ) {
difference=Math.round((circumference2-circumference1)*100)/100;
differencepercent=Math.round(((difference/circumference1)*100)*100)/100;
realspeed=Math.round((((differencepercent/100)*70)+70)*100)/100;
document.wheelsizes.difference.value=difference;
document.wheelsizes.differencepercent.value=differencepercent;
document.wheelsizes.realspeed.value=realspeed;
}
</script>
和表格是
<table border=0 align="CENTER">
<tr>
<th align=CENTER>Current wheel/tyre</th>
<th align=CENTER>New wheel/tyre</th>
</tr>
<tr>
<td align=CENTER><select name="section1">
<option value="195">190</option>
<option value="195">195</option>
<option value="205">205</option>
<option value="215">215</option>
</select>
/
<select name="profile1">
<option value="60">60</option>
<option value="65" selected>65</option>
<option value="70">70</option>
<option value="75">75</option>
<option value="80">80</option>
</select>
R
<select name="diameter1">
<option value="16">16</option>
<option value="16.5">16.5</option>
<option value="17">17</option>
<option value="18">18</option>
</select>
</td>
<td align=CENTER>
<select name="section2">
<option value="195">190</option>
<option value="195">195</option>
<option value="205">205</option>
<option value="215">215</option>
</select>
/
<select name="profile2">
<option value="60">60</option>
<option value="65" selected>65</option>
<option value="70">70</option>
<option value="75">75</option>
<option value="80">80</option>
</select>
R
<select name="diameter2">
<option value="16">16</option>
<option value="16.5">16.5</option>
<option value="17">17</option>
<option value="18">18</option>
</select>
</td>
</tr>
<tr>
<td align=CENTER>
<input type="button" name="calc1" value="Calculate" onclick="Calculate1(document.wheelsizes.section1.value, document.wheelsizes.profile1.value, document.wheelsizes.diameter1.value)">
</td>
<td align=CENTER>
<input type="button" name="calc2" value="Calculate" onclick="Calculate2(document.wheelsizes.section2.value, document.wheelsizes.profile2.value, document.wheelsizes.diameter2.value)">
</td>
</tr>
<tr>
<td align=CENTER>Current RR:<input type="text" name="rollingradius1" size=7>mm</td>
<td align=CENTER>New RR:<input type="text" name="rollingradius2" size=7>mm</td>
</tr>
<tr>
<td align=CENTER>Current circumference:<input type="text" name="circumference1" size=7>mm</td>
<td align=CENTER>New circumference:<input type="text" name="circumference2" size=7>mm</td>
</tr>
<tr>
<td colspan=2 align=CENTER>
<input type="button" name="yo" value="Click to calculate difference" onclick="Difference(document.wheelsizes.circumference1.value, document.wheelsizes.circumference2.value)">
</td>
</tr>
<tr>
<td colspan=2 align=CENTER>
Difference in circumference:<input type="text" name="difference" size=8>mm or <input type="text" name="differencepercent" size=5>%
</td>
</tr>
</table>
尽管这在某些站点上是可以使用的计算器,但是在按下计算按钮时无法获得任何结果任何建议使其正常工作
可能对您有帮助,我只为calulate1写代码”>
function getVal(ctrlid){ var e = document.getElementById(ctrlid); var result = e.options[e.selectedIndex].text; return result } function SetVal(ctrlid,values){ document.getElementById(ctrlid).value=values; } function Calculate1 ( ) { section1=getVal("section1") profile1=getVal("profile1") diameter1=getVal("diameter1") rollingradius1=Math.round((((diameter1/2)*25.4)+(section1*(profile1/100)))*100)/100; circumference1=Math.round((rollingradius1*2*3.14159)*100)/100; SetVal("rollingradius1",rollingradius1) SetVal("circumference1",circumference1) }
<table border=0 align="CENTER"> <tr> <th align=CENTER>Current wheel/tyre</th> <th align=CENTER>New wheel/tyre</th> </tr> <tr> <td align=CENTER><select name="section1" id="section1"> <option value="195">190</option> <option value="195">195</option> <option value="205">205</option> <option value="215">215</option> </select> / <select name="profile1" id="profile1"> <option value="60">60</option> <option value="65" selected>65</option> <option value="70">70</option> <option value="75">75</option> <option value="80">80</option> </select> R <select name="diameter1" id="diameter1"> <option value="16">16</option> <option value="16.5">16.5</option> <option value="17">17</option> <option value="18">18</option> </select> </td> <td align=CENTER> <select name="section2"> <option value="195">190</option> <option value="195">195</option> <option value="205">205</option> <option value="215">215</option> </select> / <select name="profile2"> <option value="60">60</option> <option value="65" selected>65</option> <option value="70">70</option> <option value="75">75</option> <option value="80">80</option> </select> R <select name="diameter2"> <option value="16">16</option> <option value="16.5">16.5</option> <option value="17">17</option> <option value="18">18</option> </select> </td> </tr> <tr> <td align=CENTER> <input type="button" name="calc1" value="Calculate" onclick="Calculate1()"> </td> <td align=CENTER> <input type="button" name="calc2" value="Calculate" onclick="Calculate2(document.wheelsizes.section2.value, document.wheelsizes.profile2.value, document.wheelsizes.diameter2.value)"> </td> </tr> <tr> <td align=CENTER>Current RR:<input type="text" name="rollingradius1" size=7 id='rollingradius1'>mm</td> <td align=CENTER>New RR:<input type="text" name="rollingradius2" size=7>mm</td> </tr> <tr> <td align=CENTER>Current circumference:<input type="text" name="circumference1" size=7 id="circumference1">mm</td> <td align=CENTER>New circumference:<input type="text" name="circumference2" size=7>mm</td> </tr> <tr> <td colspan=2 align=CENTER> <input type="button" name="yo" value="Click to calculate difference" onclick="Difference(document.wheelsizes.circumference1.value, document.wheelsizes.circumference2.value)"> </td> </tr> <tr> <td colspan=2 align=CENTER> Difference in circumference:<input type="text" name="difference" size=8>mm or <input type="text" name="differencepercent" size=5>% </td> </tr> </table>