加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php版 计算器

发布时间:2020-12-13 22:18:08 所属栏目:PHP教程 来源:网络整理
导读:1 !DOCTYPE html 2 html lang="en" 3 head 4 meta charset="UTF-8" / 5 titleDocument/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 [‘a
 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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读