Javascript 如何解决未捕获的TypeError:无法将未定义或null转换为对象
这是我的html。我想用英尺,厘米,英寸来计算高度。当我输入高度值时,我想将其转换为英寸和向上键的英尺,反之亦然。请帮帮我Javascript 如何解决未捕获的TypeError:无法将未定义或null转换为对象,javascript,jquery,html,Javascript,Jquery,Html,这是我的html。我想用英尺,厘米,英寸来计算高度。当我输入高度值时,我想将其转换为英寸和向上键的英尺,反之亦然。请帮帮我 <form name=cminch method="post"> <div> <label>feet</label> <input onkeyup="feetconvert()" name="Heightft"> <label>inch</l
<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>
只需将整个代码复制并粘贴到文件中,然后尝试运行相同的代码,如果仍然出现相同的错误,请告诉我 将一个示例签入
脚
英寸
厘米
函数roundit(which){
返回数学圆(哪一个*100)/100
}
函数cmconvert(){
带(document.cminch){
高度英尺值=圆度(高度厘米值/30.84);
HeightIn.value=圆整度(Heightcm.value/2.54);
}
}
函数inchconvert(){
带(document.cminch){
高度厘米值=圆度(高度英寸值*2.54);
高度英尺值=圆度(高度英尺值/12);
}
}
函数feetconvert(){
带(document.cminch){
高度厘米值=圆度(高度英尺值*30.48);
高度值=圆度(高度值*12);
}
}
不要将与
一起使用,这可能会使脚本的逻辑更易于理解和调试。它与当前的数据和函数配合使用时效果良好,你能告诉我错误发生的时间吗?当我在文本框中输入一个值时,它会给我错误现在我在下面得到错误未捕获引用错误:feetconvert没有在HTMLInputElement.onKeyUp中定义实际上我的代码正在运行,但当我将其包含在程序文件中时,我得到了错误,然后你的另一个文件中出现了错误代码,因为在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);
}
}
<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>