gpt4 book ai didi

按下计算按钮时 JavaScript 不执行

转载 作者:行者123 更新时间:2023-12-02 22:19:28 25 4
gpt4 key购买 nike

尝试创建计算器来计算大小差异和输出结果

这是使用的脚本。

用于计算suze基础直径的脚本查看 - https://code.sololearn.com/wahq9E8aL5I3

        <script language="JavaScript" type="text/JavaScript">
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)
}

function getVal(ctrlid2){

var e2 = document.getElementById(ctrlid2);
var result = e2.options[e2.selectedIndex].text;
return result
}
function SetVal(ctrlid2,values){
document.getElementById(ctrlid2).value=values;
}

function Calculate2 ( ) {
section2=getVal("section2")
profile2=getVal("profile2")
diameter2=getVal("diameter2")

rollingradius2=Math.round((((diameter2/2)*25.4)+(section2*(profile2/100)))*100)/100;

circumference2=Math.round((rollingradius2*2*3.14159)*100)/100;
SetVal("rollingradius2",rollingradius2)
SetVal("circumference2",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()">
</td>
<td align=CENTER>
<input type="button" name="calc2" value="Calculate" onclick="Calculate2()">
</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>

虽然这是某些网站上的可用计算器,但按计算按钮无法获得任何结果任何让它发挥作用的建议第二个计算按钮不起作用,再次尝试

最佳答案

尝试此代码,它已完全复制

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)
}


function Calculate2 ( ) {
section2=getVal("section2")
profile2=getVal("profile2")
diameter2=getVal("diameter2")

rollingradius2=Math.round((((diameter2/2)*25.4)+(section2*(profile2/100)))*100)/100;

circumference2=Math.round((rollingradius2*2*3.14159)*100)/100;
SetVal("rollingradius2",rollingradius2)
SetVal("circumference2",circumference2)
}



function Difference () {
circumference1=document.getElementById("circumference1").value
circumference2=document.getElementById("circumference2").value
difference=Math.round((circumference2-circumference1)*100)/100;
differencepercent=Math.round(((difference/circumference1)*100)*100)/100;
realspeed=Math.round((((differencepercent/100)*70)+70)*100)/100;

SetVal("difference",difference)
SetVal("differencepercent",differencepercent)
console.log("realspeed:",realspeed)
}
<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" id="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" id="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" id="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()">
</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 id="rollingradius2">mm</td>
</tr>
<tr>
<td align=CENTER>Current circumference:<input type="text" name="circumference1" id="circumference1" size=7>mm</td>
<td align=CENTER>New circumference:<input type="text" name="circumference2" id="circumference2" size=7>mm</td>
</tr>

<tr>
<td colspan=2 align=CENTER>
<input type="button" name="yo" value="Click to calculate difference" onclick="Difference()">
</td>
</tr>

<tr>
<td colspan=2 align=CENTER>
Difference in circumference:<input type="text" name="difference" size=8 id="difference">mm or <input type="text" name="differencepercent" id="differencepercent" size=5>%
</td>
</tr>

</table>

关于按下计算按钮时 JavaScript 不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59278789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com