php版 计算器

匿名 (未验证) 提交于 2019-12-02 22:11:45
 1 <!DOCTYPE html>  2 <html lang="en">  3 <head>  4     <meta charset="UTF-8" />  5     <title>Document</title>  6 </head>  7 <body>  8 <form action="" method="POST" >  9  10     <?php 11  12         $a1=(isset($_POST['a1'])) ? $_POST['a1'] : ''; 13         $a2=(isset($_POST['a2'])) ? $_POST['a2'] : ''; 14         $a3=(isset($_POST['a3'])) ? $_POST['a3'] : ''; 15  16  17         if(isset($_POST['add']) ? 'add' : ''){ 18             $a3 =  ($a1 && $a2)? ($a1 + $a2): 'NaN'; 19         } 20         if(isset($_POST['sub']) ? '-' : ''){ 21             $a3 =  ($a1 && $a2)? ($a1 - $a2): 'NaN'; 22         } 23         if(isset($_POST['mun']) ? 'mun': ''){ 24             $a3 =  ($a1===0 && $a2===0) ? ($a1 * $a2): 'NaN'; 25         } 26         if(isset($_POST['div']) ? '/' : ''){ 27             $a3 =  ($a1 && $a2) ? ($a1 / $a2) : 'NaN'; 28         } 29  30     ?> 31  32     数值1:<input type="number" name="a1" value='<?php echo $a1; ?>'/> 33     数值2:<input type="number" name="a2" value='<?php echo $a2; ?>'/> 34     <input type="submit" value="+"  name="add" /> 35     <input type="submit" value="-"  name="sub" /> 36     <input type="submit" value="*"  name="mun" /> 37     <input type="submit" value="/"  name="div" /> 38     <input  disabled='disabled' value='<?php echo $a3; ?>'> 39 </form> 40  41 </body> 42 </html>

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!