原创: αβγ 修改: me
<form id="form1" name="form1" method="post" action="">
<p> </p>
<p>
<label>请输入你的体重:
<input name="weight" type="text" size="10" value=70 />
</label>
(kg)</p>
<p>
<label>
请输入你的身高:
<input name="height" type="text" size="10" value=1.67 />
</label>
(m)</p>
<p>
<label>
您的体重指数 BMI==weight /(height^2):
<input name="bmi" type="text" size="10" />
</label>
</p>
<p>
<label>
<input type="button" name="Submit" value="测试指标" onclick="test()" />
</label>
<label>
<input type="reset" name="Submit2" value="重置" />
</label>
</p>
</form>
<script language="javascript">
function test()
{
if(!isNaN(document.form1.weight.value)&&!isNaN(document.form1.height.value))
{
var bmi =
document.form1.weight.value/(document.form1.height.value*document.form1.height.value);
document.form1.bmi.value = bmi;
if(isNaN(bmi)) {
alert('请检查输入是否正确!');
return;
}
if(bmi>24.9)
{
alert('你偏胖了!');
}else if(bmi<18.5)
{
alert('你偏瘦了!');
}else
{
alert('你体重恰当好,不胖不瘦!');
}
}else
{
alert('请检查输入是否正确!');
}
}
</script>
文章来源:
http://www.blogjava.net/beansoft/archive/2007/05/09/116202.html