以下代码是我的javascript代码。由于某些原因,当我的HTML代码中的表单按钮调用时,这将无法运行。
<script type="text/javascript" language="javascript">
function calculate(){
alert('test');
var JSlength = document.getElementById("length").value;
var JSwidth = document.getElementById("width").value;
var JSheight = document.getElementById("height").value;
var JStotal = document.getElementById("total");
var JStotal_divide = 0;
var JStotal_output = 0;
if (typeof(JSlength) === 'number') {
if (typeof(JSwidth) === 'number') {
if (typeof(JSheight) === 'number') {
if(document.getElementById('international').checked)
JStotal_divide = (JSlength * JSwidth * JSheight);
JStotal_output = (JStotal_divide / 5000);
JStotal.value = JStotal_output;
} else {
JStotal_divide = (JSlength * JSwidth * JSheight);
JStotal_output = (JStotal_divide / 6000);
JStotal.value = JStotal_output;
}
} else {
window.alert("please only enter numbers.");
}
} else {
window.alert("please only enter numbers.");
}
} else {
window.alert("please only enter numbers.");
}
}
</script>
下面的表单根本不会与javascript交互,按钮被按下并且没有任何反应,我尝试过多种东西,但由于某种原因,javascript只是不起作用?有谁可以解释为什么?
<form name="weight_calculate"> <input name="radio"
value="International" id="international" checked="checked" type="radio">International
<input name="radio" value="Domestic" id="domestic" type="radio">Domestic
<div class="header3">Length(cm)</div>
<input name="length" id="length" type="number">
<div class="header3">Width(cm)</div>
<input name="width" id="width" type="number">
<div class="header3">Height(cm)</div>
<input name="height" id="height" type="number">
<div id="divide"> </div>
<input value="Submit" id="submit" onclick="calculate();" type="button">
<div class="header3">Volumetric Weight</div>
<input name="total" id="total" readonly="true"></form>
答案 0 :(得分:0)
在if(document.getElementById('international').checked)
之后缺少花括号
应为if(document.getElementById('international').checked){