我在txt1中输了2,在txt2中输了3,运算cal()后,结果txt3中得到的是23而不是5,请教各位怎么处理?代码如下:
<script language=JavaScript>
function cal()
{
if (document.form1.txt1.value.length>0&&document.form1.txt2.value.length>0)
{
document.form1.txt3.value=document.form1.txt1.value+document.form1.txt2.value;
}
}
</script>
parseInt(numstring, [radix])
The parseInt method syntax has these parts:
Part Description
numstring Required. A string to convert into a number.
radix Optional. A value between 2 and 36 indicating the base of the number contained in numstring. If not supplied, strings with a prefix of '0x' are considered hexidecimal and strings with a prefix of '0' are considered octal. All other strings are considered decimal.
把字符串转换成数字,要习惯去查msdn或者chm文件
document.form1.txt3.value=parseInt(document.form1.txt1.value)+parseInt(document.form1.txt2.value);
function cal()
{
var a = document.form1.txt1.value;
var b = document.form1.txt2.value;
if (a.length>0 && b.length>0)
{
document.form1.txt3.value = parseFloat(a) + parseFloat(b);
}
}
<script language=JavaScript>
function cal()
{
if (document.form1.txt1.value.length>0&&document.form1.txt2.value.length>0)
{
document.form1.txt3.value=document.form1.txt1.value+document.form1.txt2.value;
}
}
</script>
parseInt(numstring, [radix])
The parseInt method syntax has these parts:
Part Description
numstring Required. A string to convert into a number.
radix Optional. A value between 2 and 36 indicating the base of the number contained in numstring. If not supplied, strings with a prefix of '0x' are considered hexidecimal and strings with a prefix of '0' are considered octal. All other strings are considered decimal.
把字符串转换成数字,要习惯去查msdn或者chm文件
document.form1.txt3.value=parseInt(document.form1.txt1.value)+parseInt(document.form1.txt2.value);
function cal()
{
var a = document.form1.txt1.value;
var b = document.form1.txt2.value;
if (a.length>0 && b.length>0)
{
document.form1.txt3.value = parseFloat(a) + parseFloat(b);
}
}
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/2092/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
评论列表