用HTML+PHP做一个简单的计算器
1、建立一个HTML文件,输入如下内容:
<html>
<head><title></title></head>
<body>
<form action="test.php" target="iframe" method="post">
<input type="text" name="first"/>
<select name="s">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" name="second" />
<input type="submit" value="计算" />
</form>
<iframe src="test.php" name="iframe" ></iframe>
</body>
</html>
(或者打开一个空白记事本,输入内容后保存为HTML文件)
保存文件为calculate.html

2、新建一个php文件,输入如下内容:
<?php
$first=$_POST["first"];
$v=$_POST["s"];
$second=$_POST["second"];
if($v=="+"){
echo $first+$second;
}elseif($v=="-"){
echo $first-$second;
}elseif($v=="*"){
echo $first*$second;
}elseif($v=="/"){
echo $first/$second;
}
?>
注意:必须保存php文档名字为test.php.
如果取了另外的名字则需要修改HTML文件中action=“另外的名字”。

3、在浏览器输入localhost/calculate.html
成功运行计算器!
