gpt4 book ai didi

javascript - 为什么我从两个差异中得到相同的结果?

转载 作者:行者123 更新时间:2023-12-02 21:47:21 24 4
gpt4 key购买 nike

       <h2>Volume</h2>

<b>Choose Convert : </b><br><br>
<input type=radio name=volConvert id="LitToGal" value="LitToGal" checked>Litre To Gallon<br>
<input type=radio name=volConvert id="GalToLit" value="GalToLit">Gallon To Litre
<br><br>

<label>
<b>Input a data: </b><br>
<input name="volData" id="inVolData" type="text" size="10">
</label><br><br>

<p>
<input type=button value="Convert" onClick="VolConvert()" />
</P>

<h4 id="result"></h4>

</div>

var 值 = parseFloat(0);var conValue = parseFloat(0);

函数 VolConvert() {

if (document.getElementById("LitToGal")) {

var inputData = parseFloat(document.getElementById("inVolData").value);
value = (inputData * 16.52);

} else if (document.getElementById("GalToLit")) {

var inputData = parseFloat(document.getElementById("inVolData").value);
value = (inputData * 113.50);
}

var conValue = value.toFixed(2);;

resultmessage = ("The converted value: " + conValue);
document.getElementById("result").innerHTML = resultmessage;

}

enter image description here

enter image description here

最佳答案

您需要比较“已检查”值

function VolConvert() {

if (document.getElementById("LitToGal").checked) {

var inputData = parseFloat(document.getElementById("inVolData").value);
value = (inputData * 16.52);

} else if (document.getElementById("GalToLit").checked) {

var inputData = parseFloat(document.getElementById("inVolData").value);
value = (inputData * 113.50);
}

var conValue = value.toFixed(2);;

resultmessage = ("The converted value: " + conValue);
document.getElementById("result").innerHTML = resultmessage;
}

关于javascript - 为什么我从两个差异中得到相同的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60220419/

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