写一个html网页,包含两个输入框和一个按钮,在第一个输入框输入表达式如“1+3”、“2*4”等等表达式后点击按钮,第二个输入框显示表达式计算结果。
请高手帮忙,谢谢。

解决方案 »

  1.   

    不刷新界面的话用Ajax比较好 建议看一下相关内容
      

  2.   

    js有个函数,就是那个3楼的eval(var),会执行里面的字符串语句。1+2写成"1+2"就行了。
      

  3.   


    <html>
        <head><title></title></head>
        <script>
            function calc(){
                var expression = document.getElementById("expre").value;
                var result = eval(expression);
                document.getElementById("result").value=result;
            }
        </script>    <body>
             <input type="text" id="expre"> <input type="button" onclick="calc()" value="给我结果"><br>
             <input type="text" id="result">
        </body>
    </html>用notepad一次打成功了,来点掌声
      

  4.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head><style>
    </style>
    </head>
    <body>
    <div>
    简单表达式:
    <input type="text" id="1" style="background-color:grey;color:red"/>
    <br/>
    <input type="button" value="点击显示计算结果:" onclick="count()"/>
    <input type="text" id="2" style="background-color:yellow;color:red"/>
    </div>
    <script>
    function  count(){
        var t1=document.getElementById("1").value;
    document.getElementById("2").value=eval(t1);
    }
    </script>
    </body>
    </html>