使用php做的简易计算器
能够进行+,-,*,/运算.
如下图
<?php if (isset($_POST['button'])) { $num1 = $_POST['num1']; $num2 = $_POST['num2']; $op = $_POST['op']; switch ($_POST['op']) { case '+': $result = $num1 + $num2; break; case '-': $result = $num1 - $num2; break; case '*': $result = $num1 * $num2; break; case '/': $result = $num1 / $num2; break; } echo <<<str <script type="text/javascript"> window.onload=function(){ document.getElementById('num1').value = '$num1'; document.getElementById('op').value = '$op'; document.getElementById('num2').value = '$num2'; document.getElementById('result').value = '$result'; } </script> str; } ?> <body> <form method="post" action=""> <input type="text" name="num1" id="num1"> <select name="op" id="op"> <option value="+">+</option> <option value="-">-</option> <option value="*">*</option> <option value="/">/</option> </select> <input type="text" name="num2" id="num2"> <input type="submit" name="button" value="="> <input type="text" name="result" id="result"> </form> </body>