js代码:
// JavaScript Document
function  getwieght(tshow,weight){
 
//年龄
var age  = weight.elements['age'].value;
//身高
var top  = weight.elements['top'].value;
//体重
var mweight  = weight.elements['mweight'].value;
//性别 2 为女  1  为男
var sex  = '';
var temp=document.getElementsByName("sex");
for (i=0;i<temp.length;i++){
	//遍历Radio
	if(temp[i].checked)
	  sex  = temp[i].value;
}
//职业
//var profession = weight.elements['profession'].value;
//学历
//var education = weight.elements['education'].value;
var msg = '';
 
// google 统计参数转换
if(sex == 2)
{
   google_sex = 'woman';
}
else
{
   google_sex = 'man';
}
if(age == -1)
{
   google_age = 'age_12';
}
else if(age == 1)
{
   google_age = 'age_12-21';
}
else if(age == 2)
{
   google_age = 'age_21-23';
}
else if(age == 3)
{
   google_age = 'age_23-25';
}
else if(age == 4)
{
   google_age = 'age_25-27';
}
else if(age == 5)
{
   google_age = 'age_27-29';
}
else if(age == 6)
{
   google_age = 'age_29-31';
}
else if(age == 7)
{
   google_age = 'age_31-33';
}
else if(age == 8)
{
   google_age = 'age_33-35';
}
else if(age == 9)
{
   google_age = 'age_35-37';
}
else if(age == 10)
{
   google_age = 'age_37-39';
}
else if(age == 11)
{
   google_age = 'age_39-41';
}
else if(age == 12)
{
   google_age = 'age_41-43';
}
else if(age == 13)
{
   google_age = 'age_43-45';
}
else if(age == 14)
{
   google_age = 'age_45-47';
}
else if(age == 15)
{
   google_age = 'age_47-49';
}
else if(age == 16)
{
   google_age = 'age_49-51';
}
else if(age == 17)
{
   google_age = 'age_51-53';
}
else if(age == 18)
{
   google_age = 'age_53-55';
}
else if(age == 19)
{
   google_age = 'age_55-57';
}
else if(age == 20)
{
   google_age = 'age_57-59';
}
else if(age == 21)
{
   google_age = 'age_59-61';
}
else if(age == 22)
{
   google_age = 'age_61-63';
}
else if(age == 23)
{
   google_age = 'age_63-65';
}
else if(age == 24)
{
   google_age = 'age_65-67';
}
else if(age == 25)
{
   google_age = 'age_67-69';
}
else if(age == 26)
{
   google_age = 'age_69';
}
else
{
   google_age = 'no choose';
}
 
 
 
 
if(sex==2){
	if(top == -1)
	{
  	 google_top_thin = 'top_women_152';
	}
	else if(top == 1)
	{
   	google_top_thin = 'top_women_152-156';
	}
	else if(top == 2)
	{
   	google_top_thin = 'top_women_156-160';
	}	
	else if(top == 3)
	{
   	google_top_thin = 'top_women_160-162';
	}
	else if(top == 4)
	{
   	google_top_thin = 'top_women_162-164';
	}
	else if(top == 5)
	{
   	google_top_thin = 'top_women_164-166';
	}
	else if(top == 6)
	{
   	google_top_thin = 'top_women_166-168';
	}
	else if(top == 7)
	{
   	google_top_thin = 'top_women_168-170';
	}
	else if(top == 8)
	{
   	google_top_thin = 'top_women_170-172';
	}
	else if(top == 9)
	{
   	google_top_thin = 'top_women_172-176';
	}
	else if(top == 10)
	{
   	google_top_thin = 'top_women_176';
	}	
	else if(top == -2)
	{
   	google_top_thin = 'top_women_176';
	}
}
else{
	if(top == -1)
	{
  	 google_top_thin = 'top_men_152';
	}
	else if(top == 1)
	{
   	google_top_thin = 'top_men_152-156';
	}
	else if(top == 2)
	{
   	google_top_thin = 'top_men_156-160';
	}	
	else if(top == 3)
	{
   	google_top_thin = 'top_men_160-164';
	}
	else if(top == 4)
	{
   	google_top_thin = 'top_men_164-168';
	}
	else if(top == 5)
	{
   	google_top_thin = 'top_men_168-172';
	}
	else if(top == 6)
	{
   	google_top_thin = 'top_men_172-176';
	}
	else if(top == 7)
	{
   	google_top_thin = 'top_men_176-180';
	}
	else if(top == 8)
	{
   	google_top_thin = 'top_men_180-184';
	}
	else if(top == 9)
	{
   	google_top_thin = 'top_men_184-188';
	}
	else if(top == 10)
	{
   	google_top_thin = 'top_men_188';
	}	
	else if(top == -2)
	{
   	google_top_thin = 'top_men_188';
	}
}
var resualt=false;
for(var i=0;i<document.formfit.sex.length;i++)
{
   
    if(document.formfit.sex[i].checked)
    {
      resualt = true;
    }
}
if(!resualt) msg = msg +"请选择性别。n";
if(top=='')	msg = msg + "请填写您的身高。n" ;
if(mweight=='')	msg = msg + "请填写您的体重。n" ;
if(mweight != '' && mweight <= 35)  msg = msg + "您填写的体重太小了不在正常范围。n" ;
if(age == '')  msg = msg + "请填写您的年龄。n" ;
//if(profession == 0)  msg = msg + "请选择您的职业。n" ;
//if(education == 0)  msg = msg + "请选择您的学历。n" ;
 
if(msg != '') 
{
   alert(msg);
   return false;	 
}
 
if(age < 12 || age > 69){
 
    alert("年龄的计算适用范围是:12岁到69岁");
	return false;
}
 
if(weight.elements['sex']){
  for(var j=0; j < weight.elements['sex'].length; j++)
    if(weight.elements['sex'][j].checked) sex = weight.elements['sex'][j].value;
}
 
if(sex==0){
 
	if(top < 152 || top > 176){
	 
		alert("女性身高的计算适用范围是:152cm到176cm。");
		return false;
	}
}else{
 
   if(top < 152 || top > 188){
	 
		alert("男性身高的计算适用范围是:152cm到188cm。");
		return false;
	}
 
 
}
 
//男性的标准 
var weight1 =" 50, 52, 52, 54, 56, 58, 61, 64, 67, 70, 51, 53, 54, 55, 57, 60, 62, 65, 69, 72, 52, 53, 55, 56, 58, 60, 63, 66, 70, 73, 52, 54, 55, 57, 59, 61, 63, 67, 71, 74, 52, 54, 55, 57, 59, 61, 64, 67, 71, 74, 53, 55, 56, 57, 59, 61, 64, 67, 71, 74, 53, 55, 56, 58, 60, 62, 65, 68, 72, 75, 54, 56, 57, 58, 60, 63, 65, 68, 72, 75, 54, 56, 57, 59, 61, 63, 66, 69, 73, 76, 55, 56, 58, 59, 61, 63, 66, 69, 73, 76, 55, 57, 58, 60, 61, 64, 66, 70, 74, 77, 55, 57, 58, 60, 62, 64, 67, 70, 74, 77, 56, 57, 58, 60, 62, 64, 67, 70, 74, 77, 56, 57, 59, 60, 62, 64, 67, 70, 74, 77, 56, 58, 59, 61, 63, 65, 67, 71, 75, 78, 56, 58, 59, 61, 63, 65, 68, 71, 75, 78, 57, 58, 59, 61, 63, 65, 68, 71, 75, 78, 57, 58, 59, 61, 63, 65, 68, 71, 75, 78, 56, 58, 59, 61, 63, 65, 68, 71, 75, 78, 56, 57, 59, 60, 62, 65, 67, 70, 74, 77, 56, 57, 58, 60, 62, 64, 67, 70, 74, 77, 56, 57, 58, 60, 62, 64, 67, 70, 74, 77, 56, 57, 58, 60, 62, 64, 67, 70, 74, 77, 56, 57, 58, 60, 62, 64, 67, 70, 74, 77, 56, 57, 58, 60, 62, 64, 67, 70, 74, 77, 56, 57, 58, 60, 62, 64, 67, 70, 74, 77"; 
//女性的标准 
var weight2 =" 46, 47, 49, 50, 51, 52, 54, 56, 57, 60, 46, 47, 49, 50, 51, 52, 54, 56, 57, 60, 46, 47, 49, 50, 51, 52, 54, 56, 57, 60, 46, 48, 49, 50, 51, 53, 55, 56, 57, 61, 47, 48, 50, 51, 52, 53, 55, 56, 58, 61, 47, 49, 51, 52, 53, 54, 56, 58, 59, 62, 48, 49, 51, 52, 53, 54, 56, 58, 59, 62, 48, 50, 51, 52, 53, 55, 57, 58, 59, 63, 49, 50, 52, 52, 53, 55, 57, 59, 60, 63, 49, 51, 53, 53, 54, 56, 59, 60, 61, 64, 50, 52, 53, 53, 55, 57, 59, 60, 61, 65, 51, 52, 54, 54, 55, 57, 59, 61, 62, 65, 51, 53, 55, 55, 56, 58, 60, 62, 63, 66, 52, 53, 55, 55, 57, 58, 60, 62, 63, 66, 52, 53, 57, 57, 57, 58, 60, 62, 63, 67, 52, 53, 56, 56, 57, 59, 60, 62, 63, 67, 52, 54, 56, 56, 57, 59, 61, 62, 63, 67, 53, 54, 56, 56, 58, 59, 61, 62, 64, 67, 53, 54, 56, 57, 58, 60, 61, 63, 64, 67, 53, 55, 56, 57, 58, 60, 61, 63, 64, 68, 53, 55, 56, 57, 58, 60, 61, 63, 64, 68, 53, 54, 56, 56, 57, 59, 61, 63, 64, 67, 52, 54, 55, 56, 57, 59, 61, 62, 63, 67, 52, 54, 55, 56, 57, 59, 61, 62, 63, 66, 52, 54, 55, 56, 57, 59, 61, 62, 63, 66, 52, 54, 55, 56, 57, 59, 61, 62, 63, 66";
 
//参数
var fit='';
var weight='';
var check='';
 
//年龄 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 
if(age < 12)          {age = -1;}
if(age>=12 && age <21){age = 1 ;}
if(age>=21 && age <23){age = 2 ;}
if(age>=23 && age <25){age = 3 ;}
if(age>=25 && age <27){age = 4 ;}
if(age>=27 && age <29){age = 5 ;}
if(age>=29 && age <31){age = 6 ;}
if(age>=31 && age <33){age = 7 ;}
if(age>=33 && age <35){age = 8 ;}
if(age>=35 && age <37){age = 9 ;}
if(age>=37 && age <39){age = 10;}
if(age>=39 && age <41){age = 11;}
if(age>=41 && age <43){age = 12;}
if(age>=43 && age <45){age = 13;}
if(age>=45 && age <47){age = 14;}
if(age>=47 && age <49){age = 15;}
if(age>=49 && age <51){age = 16;}
if(age>=51 && age <53){age = 17;}
if(age>=53 && age <55){age = 18;}
if(age>=55 && age <57){age = 19;}
if(age>=57 && age <59){age = 20;}
if(age>=59 && age <61){age = 21;}
if(age>=61 && age <63){age = 22;}
if(age>=63 && age <65){age = 23;}
if(age>=65 && age <67){age = 24;}
if(age>=67 && age <69){age = 25;}
if(age==69)           {age = 26;}
//if(age >69)           {age = -2;}
 
//性别 2 为女  1  为男
if(sex==2){
	//女性 身高 152cm 156cm 160cm 162cm 164cm 166cm 168cm 170cm 172cm 176cm 
	//if(top < 152)           {top = -1;}
	if(top>=152 && top <156){top = 1;}
	if(top>=156 && top <160){top = 2;}
	if(top>=160 && top <162){top = 3;}
	if(top>=162 && top <164){top = 4;}
	if(top>=164 && top <166){top = 5;}
	if(top>=166 && top <168){top = 6;}
	if(top>=168 && top <170){top = 7;}
	if(top>=170 && top <172){top = 8;}
	if(top>=172 && top <176){top = 9;}
	if(top==176)            {top = 10;}
	//if(top >176)            {top = -2;}
	//输出
    
	age--;
	top--;
	arrweight2 = weight2.split(",");
    weight = arrweight2[age*10+top]-2;
   
	//alert(arrweight2[age*10+top]);
}else{
	
	//男性 身高 152cm 156cm 160cm 164cm 168cm 172cm 176cm 180cm 184cm 188cm
	if(top < 152)           {top = -1;}
	if(top>=152 && top <156){top = 1;}
	if(top>=156 && top <160){top = 2;}
	if(top>=160 && top <164){top = 3;}
	if(top>=164 && top <168){top = 4;}
	if(top>=168 && top <172){top = 5;}
	if(top>=172 && top <176){top = 6;}
	if(top>=176 && top <180){top = 7;}
	if(top>=180 && top <184){top = 8;}
	if(top>=184 && top <188){top = 9;}
	if(top==188)            {top = 10;}
	if(top >188)            {top = -2;}
	
    //输出
	age--;
	top--;
	arrweight1 = weight1.split(",");
	weight = arrweight1[age*10+top]-1;
 
	//alert(arrweight1[age*10+top]);
}
 
   fit = 2*(mweight-weight);
  
   //
   if(fit <= 1 )            { check="你没有超重不用减肥,注意保持。感谢你的支持!";          } 
   
   var thea="page-product.html";
   if(tshow==2 || tshow==3){
	 thea="display.php?sn=cpyf.html";  
   }
   
   var result = '';
   
   //if(sex==0){
		if(fit >  1  &&  fit <= 10)
		{ 
			check="您需要<span class="Greed_01"><b>健康减肥"+fit+"斤</b></span>,建议您使用 <span class="Greed_01"><a href=""+thea+"#p1">基础瘦身组合</a></span>,详情请咨询在线客服。</p><br /><br /><input type="button" value="返回测试页面" onclick="tizhong()">";
			result = 'jichu_zhuhe';
		}
		
		if(fit > 10  && fit <= 20){ 
			check="您需要<span class="Greed_01"><b>健康减肥"+fit+"斤</b></span>,建议您使用 <span class="Greed_01"><a href=""+thea+"#p2">强效特惠组合</a></span>,详情请咨询在线客服。</p><br /><br /><input type="button" value="返回测试页面" onclick="tizhong()">";
			result = 'qiangxiao_zhuhe';
		}
		
		if(fit > 20 && fit <= 30 ){ 
			check="您需要<span class="Greed_01"><b>健康减肥"+fit+"斤</b></span>,建议您使用 <span class="Greed_01"><a href=""+thea+"#p3">特效巩固组合</a></span>,详情请咨询在线客服。</p><br /><br /><input type="button" value="返回测试页面" onclick="tizhong()">";
			result = 'texiao_zhuhe';
		}
		
		if(fit > 30 ){ 
			check="您需要<span class="Greed_01"><b>健康减肥"+fit+"斤</b></span>,建议您使用 <span class="Greed_01"><a href=""+thea+"#p4">终极瘦身组合</a></span>,详情请咨询在线客服。</p><br /><br /><input type="button" value="返回测试页面" onclick="tizhong()">";
			result = 'zhongji_zhuhe';
		}
		
		
	if(tshow==3){
		document.getElementById("Fplx_Right").innerHTML ="<span class="Red_01"><b>健康减肥建议:</b></span> 您的年龄身高对应标准体重为 <span class="Red_02">"+2*weight+"斤("+weight+"公斤)</span>,"+check+" ";	 	 
	}else{
		document.getElementById("TizhongB").innerHTML ="<span class="Red_01"><b>健康减肥建议:</b></span> 您的年龄身高对应标准体重为 <span class="Red_02">"+2*weight+"斤("+weight+"公斤)</span>,"+check+" ";	 	 
	}   
	
	var weight_result =  'virtual/weight_tewst/' + result;
	_gaq.push(['_setCustomVar',1,"sex",google_sex,1],
			  ['_setCustomVar',2,"age",google_age,1],
			  ['_setCustomVar',3,"profession",google_profession,1],
			  ['_setCustomVar',4,"top_thin",google_top_thin,1],
			  ['_trackPageview', weight_result]);
	
	return false;
}
 
function tizhong(){	
use="<form onsubmit="getwieght(1,this);" name="formfit" method="post" action="JavaScript:;">       <ul class="bmp_con" >       <li>        <div class="input_sex">          <label>性别: </label><input type="radio" value="1" id="sex" name="sex" class="man">男<input type="radio" value="2" id="sex" name="sex" class="lady">女                </div>               </li>        <li>        <div class="input">          <label>年龄:</label>          <input type="text" class="field-text J_Field" name="age" value="" id="" tabindex="2">          <label>周岁</label>               </div>               </li>       <li>        <div class="input">          <label>身高: </label>          <input type="text" class="field-text J_Field" name="top" value="" id="textfield2" tabindex="2">           <label>CM(厘米)</label>                </div>               </li>       <li>        <div class="input">          <label>体重:</label>          <input type="text" class="field-text J_Field" name="mweight" value="" id="" tabindex="2">          <label class="jing2" style="width:70px; height:25px; line-height:13px;  padding-left:4px;">KG(公斤)</label>                </div>               </li>       <li><input type="submit" value="计算"   class="sum"><input type="reset"  value="重置"   class="sum"></li>                                    </ul>                <div class="output_txt"  style="line-height:22px; margin-top:5px;">        健康减肥建议:请输入您的年龄、身高以及体重,亚太标准体重指数BMI测试器会根据您的标准体重,给出健康减肥建议!        </div>   		     </form>  ";
document.getElementById("TizhongB").innerHTML =use;
}
	
html代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>体重测试</title>
<meta name="Keywords" content="体重测试" />
<meta name="Description" content="体重测试" />
<style >
@charset "utf-8";
/*==============public start May 15 2011================*/
html,body,div,h1,h2,h3,h4,h5,h6,ul,li,dl,dt,dd,p,input,form{margin:0; padding:0;}
h1,h2,h3,h4,h5,h6{font-size:100%; outline-style:none;}
body{font:12px/1.5 "宋体",Arial,Lucida,Verdana,Helvetica,sans-serif; color:#3E3E3E;}
ul,dl,ol{list-style:none;}
a{text-decoration:none; color:#3E3E3E;}
a:hover{color:#FF8625;}
a,img{border:none;}
em,b{font-style:normal; font-weight:normal;}
.clearall{clear:both; content:"."; display:block;height:0; overflow:hidden;}
.display_img img{display:block;}
.side{width:268px; float:left;}
 
/*sprite*/
.coin .hd,.show_goods h6,.yonghu h6,.notic_box h6,.tz_sub_box h6{background-image:url(../images/skin/sprite_hd.jpg);}
.side .hd,.side .bt{background-image:url(../images/skin/sprite_hd.jpg);}
.side .hd{ width:268px; height:49px; text-indent:-4000px;}
.side .bd{ background:url(../images/skin/side_box_bd.jpg) 0 0 repeat-y;}
.side .bt{width:268px; height:9px; display:block; overflow:hidden; background-position:0 -381px;}
 
/*体重指数BMI*/
.bmp_con{width:230px; margin:0 auto;}
.input_sex .lady{margin-left:10px;}
.bmp_con li{ height:26px; line-height: 21px; padding-bottom:2px;}
.bmp_con .jing{width:70px; height:25px; line-height:13px; position:absolute; padding-left:4px;}
.output_txt{line-height:18px; text-align:justify; color:#156700; padding:0 20px;}
.output_txt a{font-weight:bold; color:#FF4C23;}
.output_txt a:hover{color:#289100;}
.bmp_con .sum{margin-left:30px;}
.label { float: left; height: 21px;line-height:21px;text-align: right;}
.input input {border: 1px solid #7f9db9; height: 21px; line-height: 21px; width:95px;}
.input_sex input{ line-height:21px; margin-top:8px;}
</style>
<script language="javascript" src="fit.js"></script> 
 
</head>
 
 
<body>
 
<div class="side">
	 
    <div class="bmp_box">
     <h3>欢迎测算一下您的BMI体重指数</h3>
    <div class="bd" id="TizhongA">
	<div id="TizhongB">
<form onsubmit="getwieght(1,this);" name="formfit" method="post" action="JavaScript:;">  
     <ul class="bmp_con" >
       <li>
        <div class="input_sex">
          <label>性别: </label><input type="radio" value="1" id="sex" name="sex" class="man">男<input type="radio" value="2" id="sex" name="sex" class="lady">女        
        </div>        
       </li> 
       <li>
        <div class="input">
          <label>年龄:</label>
          <input type="text" class="field-text J_Field" name="age" value="" id="" tabindex="2">
          <label>周岁</label>       
        </div>        
       </li>
       <li>
        <div class="input">
          <label>身高: </label>
          <input type="text" class="field-text J_Field" name="top" value="" id="textfield2" tabindex="2"> 
          <label>CM(厘米)</label>        
        </div>        
       </li>
       <li>
        <div class="input">
          <label>体重:</label>
          <input type="text" class="field-text J_Field" name="mweight" value="" id="" tabindex="2">
          <label class="jing2" style="width:70px; height:25px; line-height:13px;  padding-left:4px;">KG(公斤)</label>        
        </div>        
       </li>
 
       <li><input type="submit" value="计算"   class="sum"><input type="reset"  value="重置"   class="sum"></li>                              
      </ul>
        
        <div class="output_txt"  style="line-height:22px; margin-top:5px;">
        健康减肥建议:请输入您的年龄、身高以及体重,亚太标准体重指数BMI测试器会根据您的标准体重,给出健康减肥建议!
        </div>   
		
     </form> 
    </div>
	</div>
     </div>		
</div>
</body>
</html>	
评论