标签:style blog io color os for sp div on
<?php error_reporting(E_ALL & ~E_NOTICE); if( isset($_POST[‘sub‘])){ $bz = true; $errormess = "有以上问题<br>"; if($_POST[‘num1‘] == ""){ $bz = false; $errormess = "第一个数不能为空<br>"; }else{ if(!is_numeric($_POST[‘num1‘])){ $bz = false; $errormess .= "不是数字不能计算<br>"; } } if($_POST[‘num2‘] == ""){ $bz = false; $errormess = "第二个数不能为空<br>"; }else{ if(!is_numeric($_POST[‘num2‘])){ $bz = false; $errormess .= "不是数字不能计算<br>"; } } if($bz){ $sum = ""; switch($_POST[‘ysf‘]){ case ‘+‘ :$sum = $_POST[‘num1‘] + $_POST[‘num2‘];break; case ‘-‘ :$sum = $_POST[‘num1‘] - $_POST[‘num2‘];break; case ‘*‘ :$sum = $_POST[‘num1‘] * $_POST[‘num2‘];break; case ‘/‘ :$sum = $_POST[‘num1‘] / $_POST[‘num2‘];break; case ‘%‘ :$sum = $_POST[‘num1‘] % $_POST[‘num2‘];break; } } } echo ‘<br>‘; ?> <html> <head> <title>计算器</title> </head> <body> <table border="0" width="200" align="center"> <form action="jsq.php" method="post"> <caption><h1>简单计算器</h1></caption> <tr> <td> <input type="text" size="10" name="num1" value="<?php echo $_POST[‘num1‘]?>"><br> </td> <td> <select name="ysf"> <option <?php echo $_POST[‘ysf‘] == "+" ? "selected" : ""?> value="+">+</option> <option <?php if($_POST[‘ysf‘] == "-") echo "selected"?> value="-">-</option> <option <?php if($_POST[‘ysf‘] == "*") echo "selected"?> value="*">*</option> <option <?php if($_POST[‘ysf‘] == "/") echo "selected"?> value="/">/</option> <option <?php if($_POST[‘ysf‘] == "%") echo "selected"?> value="%">%</option> </select> </td> <td> <input type="text" size="8" name="num2" value="<?php echo $_POST[‘num2‘]?>"><br> </td> <td> <input type="submit" name="sub" value="计算"> </td> </tr> <tr > <td colspan="4"> <?php if($bz){ echo "计算结果:{$_POST[‘num1‘]} {$_POST[‘ysf‘]} {$_POST[‘num2‘]} = {$sum}"; }else{ echo "{$errormess}"; } ?> </td> </tr> </form> </table> </body> </html>
标签:style blog io color os for sp div on
原文地址:http://www.cnblogs.com/lcpholdon/p/4077324.html