标签:for 简单计算器 input alt str action info style get
使用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>
标签:for 简单计算器 input alt str action info style get
原文地址:https://www.cnblogs.com/wjw9/p/10962739.html