[英]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.