input动态运算时,小数点不起作用.求解.
<script>
function tmulIt()
{
var num11 = parseInt(document.all.field_11.value,10);
var num12 = parseInt(document.all.field_12.value,10);
var num17 = parseInt(document.all.field_17.value,10);
if(isNaN(num11))
num11 = 0;
if(isNaN(num12))
num12 = 0;
if(isNaN(num17))
num17 = 0;
document.all.field_18.value = num11+num12+num17;
}
</script>
<input name= "field_11 " type= "text " size= "50 " onpropertychange= "tmulIt() ">
<input name= "field_12 " type= "text " size= "50 " onpropertychange= "tmulIt() ">
<input name= "field_17 " type= "text " size= "50 ">
当输入小数点时.不起作用.
------解决方案--------------------var num11 = parseFloat(document.all.field_11.value,10);
var num12 = parseFloat(document.all.field_12.value,10);
var num17 = parseFloat(document.all.field_17.value,10);
------解决方案--------------------用parseFloat()
------解决方案--------------------parseInt函数将字符串转换成整型
要用浮点型,请用parseFloat()