简体   繁体   English

如何解决Uncaught TypeError:无法将undefined或null转换为对象

[英]how to solve Uncaught TypeError: Cannot convert undefined or null to object

This is my html. 这是我的html。 I want to calculate height in feet, cm, inch. 我想计算以英尺,厘米,英寸为单位的高度。 When I enter height value then I want to convert it into inch and feet on key up and vise-versa. 当我输入高度值时,我想将其转换为英寸和英尺,反之亦然。 Please help me. 请帮我。

<form name=cminch method="post">
    <div>
        <label>feet</label>
        <input onkeyup="feetconvert()" name="Heightft">
        <label>inch</label>
        <input onkeyup="inchconvert()"  name="HeightIn">
        <label>Cm</label>
        <input onkeyup="cmconvert()"" name="Heightcm"> 
    </div>
</form>

This is my JavaScript function 这是我的JavaScript函数

function roundit(which){
    return Math.round(which*100)/100
}

function cmconvert(){
    with (document.cminch){
        Heightft.value = roundit(Heightcm.value/30.84);
        HeightIn.value = roundit(Heightcm.value/2.54);
    }
}
function inchconvert(){
    with (document.cminch){
        Heightcm.value = roundit(HeightIn.value*2.54);
        Heightft.value=roundit(HeightIn.value/12);
    }
}
function feetconvert(){
    with (document.cminch){
        Heightcm.value=roundit(Heightft.value*30.48);
        HeightIn.value=roundit(Heightft.value*12);
    }
}

Just copy and paste whole code in your file try running the same and let me know if you still getting the same error. 只需将整个代码复制并粘贴到您的文件中,然后尝试运行相同的代码,并让我知道您是否仍然遇到相同的错误。

Check an example into JSFiddle 将示例检入JSFiddle

<form name="cminch" method="post">
    <div>
      <label>feet</label>
      <input onkeyup="feetconvert()" name="Heightft">
      <label>inch</label>
      <input onkeyup="inchconvert()"  name="HeightIn">
      <label>Cm</label>
      <input onkeyup="cmconvert()" name="Heightcm"> 
    </div>
</form>

<script>
    function roundit(which){
        return Math.round(which*100)/100
    }

    function cmconvert(){
        with (document.cminch){
            Heightft.value = roundit(Heightcm.value/30.84);
            HeightIn.value = roundit(Heightcm.value/2.54);
        }
    }
    function inchconvert(){
        with (document.cminch){
            Heightcm.value = roundit(HeightIn.value*2.54);
            Heightft.value=roundit(HeightIn.value/12);
        }
    }
    function feetconvert(){
        with (document.cminch){
            Heightcm.value=roundit(Heightft.value*30.48);
            HeightIn.value=roundit(Heightft.value*12);
        }
    }
</script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的TypeError:无法将未定义或null转换为对象 - Uncaught TypeError: Cannot convert undefined or null to object 如何解决这个“Uncaught TypeError:无法将undefined或null转换为object” - How to resolve this “ Uncaught TypeError: Cannot convert undefined or null to object ” 未捕获的类型错误:无法在推送时将 undefined 或 null 转换为对象(<anonymous> ) - Uncaught TypeError: Cannot convert undefined or null to object at push (<anonymous>) 未捕获的类型错误:无法将未定义或 null 转换为 object React JS - Uncaught TypeError: Cannot convert undefined or null to object React JS JavaScript 未捕获类型错误:无法将未定义或 null 转换为 object - JavaScript Uncaught TypeError: Cannot convert undefined or null to object json数据错误未捕获的TypeError:无法将未定义或null转换为对象 - json data error Uncaught TypeError: Cannot convert undefined or null to object 未捕获的类型错误:无法将未定义或 null 转换为 object 反应 - Uncaught TypeError: Cannot convert undefined or null to object React 如何解决 Uncaught TypeError: Cannot convert null or undefined to object? - How do I resolve a Uncaught TypeError: Cannot convert null or undefined to object? JS setter 返回 ''undefined'' 并且 getter 导致 Uncaught TypeError TypeError: Cannot convert undefined or null to object - JS setters return ''undefined'' and the getter causes Uncaught TypeError TypeError: Cannot convert undefined or null to object 如何解决 TypeError:无法将 undefined 或 null 转换为对象 - How to resolve TypeError: Cannot convert undefined or null to object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM