php版 计算器

 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>

猜你喜欢

转载自www.cnblogs.com/vaso-me/p/11223630.html