[HTML] 纯文本查看 复制代码
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<!-- <meta name=description content=""> -->
<!-- <meta name=viewport content="width=device-width, initial-scale=1"> -->
<title>计算器页面</title>
</head>
<body>
<form action="" method="POST" accept-charset="utf-8">
<input type="text" name="num1",id="">
<select name="operator" id="">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="">/</option>
</select>
<input type="text" name="num2" id="">&
<input type="submit" value="计算">
<?php
if(empty($_POST)){
die;}
$num1=$_POST['num1'];
$num2=$_POST['num2'];
$op=$_POST['operator'];
var_dump($num1,$num2,$op);
if(empty($num1)||empty($num2)){
die("参数非法");
}
// 处理计算问题
$res="";
if($op =='+')
$res=$num1+$num2;
elseif($op =='-')
$res=$num1-$num2;
elseif ($op =='/')
$res=$num1/$num2;
else
$res=$num1*$num2;
echo "结果为:",$res;
?>
}
</body>
</html>