Jgs转换器的kgs和LBs

时间:2014-03-11 02:19:06

标签: javascript html5


Javascript实现和Html表单

您好我创建了一个代码,可以帮助我根据切换案例中使用的信息获得权重,当单击任一单选按钮时,结果将以Kgs或Pounds的形式提供。但在我的情况下,每次输出都是被显示为NAN。请指导我在哪里犯错误。

另外,如果你能指导我最好的方式。我会对此表示感谢 由于我是javascript的新手,我会请求指导我。谢谢


<form>
    HEIGHT:
    <input type=text name="height" id="wt1" onChange="convert(this.form);" onfocus="reset()" placeholder="feet" value="0" />Feet
    <br>
    <br>
    <br>
    <br>&nbsp;
    <label>
        <br>WEIGHT IN Kg:
        <input name="weight" id="wt2" type="radio" onClick="convert(this.form);" class="wt" />Kg</label>
    <label>
        <br>WEIGHT IN Pounds:
        <input name="weight" id="wt3" onClick="convert(this.form);" type="radio" class="wt" />Lb</label>
    <label>
        <br>WEIGHT :
        <input name="weight34" type="text" id="wt4" placeholder="Kg/Lb" onfocus="reset()" />
    </label>
</form>
<script type="text/javascript">
    function convert(form) {
        var calweight1;
        var calweight2;
        var finalcalweight;
        var heightvalue;
        heightvalue = form.height.value;
        if (form.weight[0].checked) {
            switch (isNaN(parseInt(heightvalue))) {
            case 5.0:
                calweight1 = 50 + 2.3 + 5.0 + 1.9;
                break;
            case 5.1:
                calweight1 = 50 + 2.3 + 5.1 + 3.8;
                break;
            case 5.2:
                calweight1 = 50 + 2.3 + 5.2 + 5.4;
                break;
            }
            finalcalweight = Math.round(calweight1);
        } else if (form.weight[1].checked) {
            switch (isNaN(parseInt(heightvalue))) {
            case 5.0:
                calweight2 = 106.0 + 5.0;
                break;
            case 5.1:
                calweight2 = 5.1 + 112.0;
                break;
            case 5.2:
                calweight2 = 5.2 + 118.0;
                break;
            }
            finalcalweight = Math.round(calweight2);
        }
        form.weight34.value = finalcalweight;
    }
</script>

1 个答案:

答案 0 :(得分:0)

通过快速查看,我可以看到您使用isNaN。请注意,它是一个布尔函数并返回true或false。实际上,您swtich truefalse而不是值{{1}}。 所以,这确实是问题所在,问题是 fixed