- UID
- 1
- 贡献
- 844
- 金币
- 1540
- 主题
- 520
- 在线时间
- 333 小时
- 注册时间
- 2022-1-15
- 最后登录
- 2024-11-12
|
发表于 2022-11-23 14:53:21
| 344 |
0 |
显示全部楼层
|阅读模式
php算法计算案例教程分享
效果如图所示:
代码如下:
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <?php
- if(isset($_POST['button'])){
- $jhy = $_POST['diyi'];
- $jhe = $_POST['dier'];
- $disan = "0";
- switch($_POST['suan']){
- case '0':
- $disan = (int)$jhy + (int)$jhe;
- $suan = $_POST['suan'];
- break;
- case '1':
- $disan = $jhy - $jhe;
- $suan = $_POST['suan'];
- break;
- case '2':
- $disan =$jhy * $jhe;
- $suan = $_POST['suan'];
- break;
- case '3':
- $disan =$jhy / $jhe;
- $suan = $_POST['suan'];
- break;
- }
- echo <<<jinhei
- <script type="text/javascript">
- window.onload=function(){
- document.getElementById('disan').value='$disan';
- document.getElementById('diyi').value='$jhy';
- document.getElementById('dier').value='$jhe';
- document.getElementById('suan').value='$suan';
- }
- </script>
- jinhei;
- }
- ?>
- <form method="post" action="">
- <input type="text" name="diyi" id="diyi">
- <select name="suan" id="suan">
- <option value="0">+</option>
- <option value="1">-</option>
- <option value="2">*</option>
- <option value="3">/</option>
- </select>
- <input type="text" name="dier" id="dier">
- <input type="submit" name="button" value="=">
- <input type="text" value="0" name="disan" id="disan">
- </form>
- </body>
- </html>
复制代码
|
|