这个非常简单,先看看效果
自动计算 +-*/=
贴出代码
<head>
<title></title> <script type="text/javascript"> function Calculate() { var i = document.getElementById("a").value; var j = document.getElementById("b").value; var k = document.getElementById("c"); var opera = document.getElementById("select").value; if (opera == 0) { k.value = parseInt(i) + parseInt(j); } else if (opera == 1) { k.value = i - j; } else if (opera == 2) { k.value = parseFloat(i * j).toFixed(2); } else { k.value = parseFloat(i / j).toFixed(2); } } </script></head><body> <div style="text-align:center;"> 自动计算<br /> <input type="text" id="a" οnkeyup="Calculate()"/> <select id="select" οnchange="Calculate()"> <option value="0">+</option> <option value="1">-</option> <option value="2">*</option> <option value="3">/</option> </select> <input type="text" id="b" οnkeyup="Calculate()"/>= <input type="text" id="c"/> <input type="button" id="calculate" value="计算" οnclick="Calculate()"/> </div></body>