注意下类型问题就可以了
parseInt()

解决方案 »

  1.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>一个简单的计算器</title>
    <style type="text/css">
    .style1 {color: green}
    input.style_{background-color:#fff;border:0}
    body,td,th {font-size: 9pt; color: #000000;}
    body { background-color: lavender;}
    </style>
    </head>
    <script language="javascript1.2">
    function Validator()
    {
    var aa =document.thistest.the1.value;
    var cc =  document.thistest.the3.value;
    var count=0;
    if (aa=="")
    {
    alert ("您的第一个数没有输入!\n\n请填写完整。");
    document.thistest.the1.select();
    return false;
    }
    if (cc=="")
    {
    alert ("您的第二个数没有输入!\n\n请填写完整。");
           document.thistest.the3.select();
    return false;
    }
    var tt="";
    var radios = document.all.the2;
    for(var i=0; i<radios.length; i++)
    {
       if(radios[i].checked)
    {
     tt=radios[i].value; 
         count += 1; 
      document.thistest.the4.value=eval(aa+tt+cc);
    }
    }
    if(count==0)
    {
    alert("您还没有选择运算符!\n\n请填写完整。");
    return false;
    }
    if(document.thistest.elements['the2'].length<0)
    {
    alert("您还没有选择运算符!\n\n请填写完整。");
    return false;
    }if ((cc==0)&&(radios[3].checked))
    {
    alert ("除数不能为零。");
    document.thistest.the4.value="";
          return false;
    }
    }
    </script>
    <body>
    <p><span class="style1">一个简单的计算器</span>:</p>
    <p>当用户点击“=”按扭时能根据用户选择的操作符将结果计算出来:</p>
    <p>要求:
    <ol>
      <li>能判断操作数完整输入后才计算</li>
      <li>除数不能为0</li>
    </ol></p>
    <table width="100%"  border="0">
    <form  name="thistest">
      <tr>
        <td width="23%" height="38">
        <input name="the1" type="text" size="20" class="style_"></td>
        <td width="6%">
          <p>
            <input type="radio" name="the2" value="+"> + <br>
            <input type="radio" name="the2" value="-"> - <br>
        <input type="radio" name="the2" value="*"> * <br>
        <input type="radio" name="the2" value="/"> / <br>
          
          </td>
        <td width="18%">
          <input name="the3" type="text" class="style_" id="the3" size="20"> </td>
        <td width="6%">
        <input type="button" name="Submit" value="  =  " class="style_" onclick="return Validator()"></td>
        <td width="47%">
        <input name="the4" type="text" class="style_" id="the4" size="20"></td>
      </tr>
      </form></table></body></html>