解决方案 »

  1.   

    name="text" 
    改成
    id="text"代码中使用document.getElementById("text")得到这个对象。而不是简单地text.value等 
      

  2.   

    敢情这是来让调代码的啊。
    按照楼上的 解决后 你的text undefined的问题解决的,但是还是有各种各样的问题,
    楼主加油。
      

  3.   


    我发现他在IE可以用的只是在Google Chrome就不可以了,受教了
      

  4.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>计算器</title>

    </head>
    <body>
    <script type="text/javascript">
    var isnnum=false;
    var n1=0;
    var fu="";
    var zong=0;
    var isdian=false;

    function Backspace() 
    {
    var text_ing =text.value;
    if(text_ing!=0)
    {
    var text_str=String(Math.abs(text_ing));
    if (text_ing.length==1||text_str.length==1)
    {
    text.value="0";
    isdian=false;
    }
    else
    {
    text.value=text_ing.substring(0,text_ing.length-1);
    } }

    }
    function zf()
    {
    var str=parseFloat(text.value);
    if (str>0)
    {
    text.value="-"+str;
    }
    if (str<0) 
    {
    text.value=Math.abs(str);
    }
    } function num(n)
    {
    if (isnnum==true)
    {
    if (text.value=="0.")
     {
      text.value=text.value+n;
     }
     else
     {
      text.value=n;
     }
     isnnum=false;
    }
    else
    {
    if (text.value=="0") 
    {
    text.value=n;
    }
    else
    {
    text.value=text.value+n;
    }
    }
    n1=parseFloat(text.value);
    }
    function dian()
    {
    var isfirst=isfloor();
    if(isnnum==true||text.value=="0")
    {
    text.value="0.";
    }
    if (isnnum==false&&isfirst==true) 
    {
    text.value="0.";
    }
    else if (isdian==false)
     {
      if (parseFloat(text.value)=="0")
       {
        text.value="0.";
       }
       else if (isfirst==true)
       {
        text.value=text.value;
       }
       else
       {
        text.value=text.value+".";
       }
       isdian=true;
     }
    }
    function isfloor()
    {
    var int1=parseFloat(text.value);
    var int2=Math.floor(int1);
    if (int1>int2)
    {
    return true;
    }
    else
    {
    return false;
    }
    }
    function qingkong()
    {
    isdian=isnnum=false;
    zong=parseFloat(text.value);
    text.value="0";
    isnnum=true;
    fu=base="";
    dd=jsq=zong=n1=0;
    }
    function isXiao(n)
    {
    var int1=parseFloat(text.value);
    var int2=Math.floor(int1);
    if (int1>int2)
    {
    return true;
    }
    else
    {
    return false;
    }
    }
    function js(s)
    {
    var lin= parseFloat(n1);
    if ((fu=="=")&&(s=="="))
    {
    if (isXiao(zong)==true)
     {
      text.value=zong.toFixed(4);
     }
     else
     {
      text.value=zong;
     }

    }
    else if((fu=="=")&&(s==("*")||s==("+")||s==("-")||s==("/")))
    {
    if (isXiao(zong)==true)
     {
      text.value=zong.toFixed(4);
     }
     else
     {
      text.value=zong;
     }
     fu=s;
    }
    else
    {
    if ("+"==fu)
     {zong+=lin;}
    else if ("-"==fu)
     {
      zong-=lin;
     }
     else if ("/"==fu) 
     {
      zong/=lin;
     }
     else if ("*"==fu) 
      {
      zong*=lin;
      }
      else
      {
      zong=lin;
      }
      if (isXiao(zong)==true) 
      {
      text.value=zong.toFixed(4);
      }
      else
      {
      text.value=zong;
      }
      fu=s;
    }
    isnnum=true;
    }
    </script><table width="213" height="214" border="1" cellspacing="5" style=" background-color:#CCFFFF">
    <tr>
    <td id="td1" colspan="6" height="20">
    <input type="text" name="text" value="0" size="33" style="background-color:#FFFFFF;font-size:9pt;color:#333333;border:1px solid #999999; cursor:text">
    </td>
    </tr>
    <tr>
    <td align="right" height="30" colspan="2">
    <div align="left">
    <input type="button" name="back" value="Backspace" onclick="Backspace()" >
    </div>
    </td>
    <td align="right">
    <div align="left">
    <input align="right" type="button" name="C" value="C" onclick="qingkong()">
    </div>
    </td>
    <td>
    <input type="button" name="Button" value=" = " onclick="js('=')">
    </td>
    </tr>
    <tr>
    <td width="47" height="28">
    <input type="button" name="A7" value=" 7 " onclick="num(7)">
    </td>
    <td width="50">
    <input type="button" name="A8" value=" 8 " onclick="num(8)">
    </td>
    <td width="47">
    <input type="button" name="A9" value=" 9 " onclick="num(9)">
    </td>
    <td width="42">
    <input type="button" name="chu2" value=" / " onclick="js('/')">
    </td>
    </tr>
    <tr>
    <td width="47" height="28">
    <input type="button" name="A4" value=" 4 " onclick="num(4)">
    </td>
    <td width="50">
    <input type="button" name="A5" value=" 5 " onclick="num(5)">
    </td>
    <td width="47">
    <input type="button" name="A6" value=" 6 " onclick="num(6)">
    </td>
    <td width="42">
    <input type="button" name="cheng" value=" * " onclick="js('*')">
    </td>
    </tr>
    <tr>
    <td width="47" height="28">
    <input type="button" name="A1" value=" 1 " onclick="num(1)">
    </td>
    <td width="50">
    <input type="button" name="A2" value=" 2 " onclick="num(2)">
    </td>
    <td width="47">
    <input type="button" name="A3" value=" 3 " onclick="num(3)">
    </td>
    <td width="42">
    <input type="button" name="jian" value=" - " onclick="js('-')">
    </td>
    </tr>
    <tr>
    <td width="47" height="28">
    <input type="button" name="A0" value="0" onclick="num(0)">
    </td>
    <td width="50">
    <input type="button" name="jgj" value="+/-" onclick="zf()">
    </td>
    <td width="47">
    <input type="button" name="dian" value=" . " onclick="dian()">
    </td>
    <td width="42">
    <input type="button" name="jia" value=" + " onclick="js('+')">
    </td>
    </tr>
    </table>
    </body>
    </html>
    在IE调试没有出错,在Google Chrome就显示text没有定义
      

  5.   

    ie可以直接写 text.value
    非IE不支持