1.简单的标准体重计算器
<meta http-equiv="Content-type" Content="text/html;charset=UTF-8;" />
<html>
<head>
<title>PHP交互页面演示</title>
</head>
<body>
<form method="post">
请输入身高:<input type="text" name="height"/>
<input type="submit" name="button" value="提交"/>
</form>
</body>
</html>
<?php
if(isset($_POST["button"])) //isset()检查变量是否存在-"提交"(name="button")是否被按下
{ //$_POST数组是否有键值为button的成员变量
$Height=$_POST["height"];
$Weight=($Height-100)*0.9;
echo $Height."cm"."标准体重为:".$Weight."kg";
}
?>
2.使用javascript
<meta http-equiv="Content-type" Content="text/html;charset=UTF-8;" />
<html>
<head>
<title>JavaScript页面</title>
</head>
<body >
<form name="form1">
<table align="center" bgcolor="#CCFFCC">
<tr><td colspan=2><div align="center">标准体重计算器</div></td></tr>
<tr><td colspan=2><div align="center">☆☆☆</div></td></tr>
<tr><td>请输入身高cm:<input type="text" name="height" /></td>
<td><input type="button" name="button" value="提交" onclick="hw()"/></td></tr>
<tr><td colspan=2><hr></td></tr>
<tr><td colspan=2><div align="center" id="result">输入身高单击提交就有结果了哦</div></td></tr>
</table>
</form>
<script langauge="JavaScript">
function hw(){
h=form1.height.value;
w=(h-100)*0.9;
document.getElementById("result").innerHTML=h+"cm"+"标准体重为:"+w+"kg";
}
</script>
</body>
</html>