js 代码:
<script type="text/javascript">
var btn = document.getElementById("btn"),reset = document.getElementById("reset"),result = document.getElementById("Result2");
function ceshi(){
var man = document.getElementById("man"),woman = document.getElementById("woman"),father = document.getElementById("fh"),mother = document.getElementById("mh");
var g1 = document.getElementById("g1"),g2 = document.getElementById("g2");
//var isNum = /^-?d+(?:.d*)?(?:e[+-]?d+)?$/i;
var isNum =/^[0-9.]*$/;
var parseF = parseInt(father.value);
var parseM = parseInt(mother.value);
if(parseF>=250||parseF<=55||parseM>=250||parseM<=55)
{
alert("您好 !输入父母身高要都是55-250之间!");
}
else if(!isNum.test(father.value)||!isNum.test(mother.value)||father.value==''||mother.value=='')
{
alert('输入父母身高不是数字!');
}
else
{
if(man.checked){
if(!isNum.test(father.value)) return;
//g1.innerHTML = parseInt(((parseF+parseM)/2)*1);
//alert(((parseF+parseM)/2)*1.16);
g1.value=parseInt(((parseF+parseM)/2)*1);
g2.value=parseInt(((parseF+parseM)/2)*1.16);
//g2.innerHTML = parseInt(((parseF+parseM)/2)*1.16);
}else if(woman.checked){
if(!isNum.test(mother.value)) return;
g1.value = parseInt((parseF*0.913+parseM)/2);
g2.value = parseInt((parseF+parseM)/2);
}else{
alert('请选择性别!');
}
}
}
reset.onclick = function(){
result.innerHTML = '未知';
father.value = '例:175';
mother.value = '例:165';
};
function resetw()
{
document.getElementById("fh").value='';
document.getElementById("mh").value='';
document.getElementById("g1").value='';
document.getElementById("g2").value='';
}
</script>
html代码:
<table width="212" border="0" cellspacing="0" cellpadding="2">
<tr>
<td width="63" height="35" align="right">性 别:</td>
<td width="67" height="35">
<input type="radio" name="sex" value="1" id="man"/>男
</td>
<td width="70" height="35">
<input type="radio" name="sex" value="0" id="woman"/>女
</td>
</tr>
<tr>
<td width="63" height="35" align="right">父身高:</td>
<td height="35" colspan="2">
<label>
<input type="text" name="fg" id="fh" style="width:100px; height:20px;" />厘米
</label>
</td>
</tr>
<tr>
<td width="63" height="35" align="right">母身高:</td>
<td height="35" colspan="2">
<label>
<input type="text" name="mg" id="mh" style="width:100px; height:20px;" />厘米
</label>
</td>
</tr>
<tr>
<td width="63" height="35" align="right"> </td>
<td height="35">
<label>
<input type="button" name="test" value="提交" id="btn" onclick="ceshi()"/>
</label>
</td>
<td height="35">
<label>
<input type="submit" name="Submit2" value="重置" onclick="resetw()" />
</label>
</td>
</tr>
</table>
评论