BMI计算器

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style type="text/css">
*{
margin: 0px;
padding: 0px;
}
body{

font-size: 63%;
}
.clearfix:after{
content:'';
display: block;
clear:both;
}
.clearfix{
zoom:1;
}
.bmi-box{
width:302px;
}
.bmi-box input{
width:150px;
}
.cueBox{
font-size: 1.6em;
/* line-height: 180%; */
text-align: left;
margin: 5px 0px;
padding: 0px;
}
#cue{
border: 1px dotted #ddd;
background-color: #ffa;
margin: 10px 0px 15px 0px;
padding: 2px;
}
.tit{
width:120px;
height: 2.4em;
font-size: 1.4em;
/* line-height: 180%; */
float:left;
}
.msg input{
width:170px;
padding-left:10px;
background: #eff8ff;
border: 1px solid #999;
font-size: 1.2em;
line-height: 1.6em;
float:left;
}
.button{
padding: 2px 10px;
font-size: 1.0em;
line-height: 100%;
margin:0 auto;
}
.msg{
width:100%;
}
</style>
</head>
<head>
<script>
function idealweight(a){
var x=(a-100)*0.9;
return x;
}

function bmi(a,b){
var bmi=b*1.0/((a*1.0/100)*(a*1.0/100));
return bmi;
}

function Cal(form){
var a=eval(form.height.value);
var b=eval(form.weight.value);
var BMI=eval(form.BMI.value);

form.IW.value=idealweight(a);
form.BMI.value=bmi(a,b);
disp_alert(bmi(a,b));
}

function disp_alert(bmi){
if (bmi < 18.5)
{
document.getElementById('cueBox').style.display='block';
document.getElementById('cue').innerHTML="你的体重太轻,要多吃点哟!";
// alert("你的体重太轻,要多吃点哟!");
}
else if (bmi >= 18.5 && bmi < 25)
{
////////////////////////////////
// alert("亲,你的体重正常,要继续保持哟!"); //
////////////////////////////////
document.getElementById('cueBox').style.display='block';
document.getElementById('cue').innerHTML="亲,你的体重正常,要继续保持哟!";
}
else if (bmi >= 25 && bmi< 30)
{
document.getElementById('cueBox').style.display='block';
document.getElementById('cue').innerHTML="亲,您的体重过重,要减肥了!";
//////////////////////////////
// alert("亲,您的体重过重,要减肥了!"); //
//////////////////////////////
}
else
{
document.getElementById('cueBox').style.display='block';
document.getElementById('cue').innerHTML="亲,你确实要减肥了!";
//////////////////////////
// alert("亲,你确实要减肥了!"); //
//////////////////////////
}
}

</script>
</head>
<body>
<form method=post class="bmi-box">
<div class="msg clearfix">
<p class="tit">你的身高(cm):</p><input type="text" name="height">
</div>
<div class="msg clearfix">
<p class="tit">你的体重(kg):</p><input type="text" name="weight">
</div>
<div class="clearfix">
<p class="tit"></p>
<input type="button" class="button" value="开始计算" onclick="Cal(this.form)">
</div>
<div class="cueBox" id="cueBox" style="display:none;">
<div id="cue"></div>
</div>
<div class="msg clearfix">
<p class="tit">你的理想体重(kg):</p><input type="text" name="IW">
</div>
<div class="msg clearfix">
<p class="tit">您的BMI值:</p><input type="text" name="BMI">
</div>
</form>
</body>
</html>

posted @ 2017-08-29 13:05  Viva_nan  阅读(406)  评论(0编辑  收藏  举报