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);

解决方案 »

  1.   

    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);
      }
    }
      

  2.   

    document.form1.txt3.value=document.form1.txt1.value+document.form1.txt2.value;+表示字符相连, parseFloat(a) + parseFloat(b);
      

  3.   

    var a = "1" ;
    var b = "2" ;
    var a2 = eval( a ) ;
    var b2 = eval( b ) ;
    alert( a2 + b2 )
      

  4.   

    呵呵,教你一招,用a-(-b)就行了,这是由于只有把变量看成数字才能执行,所以结果相当于数字的 a+b而不是字符串连接
      

  5.   

    用parseInt()函数来将字符转化为数字或者象楼上那样用*1.0的方法
      

  6.   

    我也碰到这样的情况。用switch case是判断option的value没有结果。
    直接用value表示的是字符串吧。
    用parseInt(value)就好了。