黑马程序员技术交流社区
标题:
计算器
[打印本页]
作者:
AfraHu
时间:
2017-1-19 10:44
标题:
计算器
<!DOCTYPE html>
<html>
<head>
<meta charset="{CHARSET}">
<title>calculator</title>
</head>
<body>
<?php
if(!empty($_POST)){
$num1 = $_POST['data1'];
$num2 = $_POST['data2'];
$fuhao = $_POST['yunsuanfu'];
if($fuhao == '+'){
$jieguo = $num1 + $num2;
}
else if($fuhao == '-'){
$jieguo = $num1 - $num2;
}
else if($fuhao == '*'){
$jieguo = $num1 * $num2;
}
else if($fuhao == '/'){
$jieguo = $num1 / $num2;
}
}
else{
$jieguo = "";
$num1 = "";
$num2 = "";
$fuhao = "";
}
?>
<form action="" method="post">
<input type="text" name="data1" value="<?php echo $num1; ?>" />
<select name="yunsuanfu">
<option value="+" >+</option>
<option value="-" <?php if($fuhao=='-') echo 'selected="slected"'; ?> >-</option>
<option value="*" <?php if($fuhao=='*') echo 'selected="slected"'; ?> >*</option>
<option value="/" <?php if($fuhao=='/') echo 'selected="slected"'; ?> >/</option>
</select>
<input type="text" name="data2" value="<?php echo $num2; ?>" />
<input type="submit" value="=" />
<input type="text" name="result" value="<?php echo $jieguo; ?>" />
<!--<input type="text" name="result" value="<?php if(!empty($_POST)){echo $jieguo;} ?>" />
</form>
</body>
</html>
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2