js实现子女身高预测代码
js实现子女身高预测代码,java身高预测程序教程如下:
1.输入父亲身高
2.输入母亲身高
计算结果:预测子女身高
js实现代码:
function setKeyup(obj) {
if (!obj.value) return false;
re = /^[\d\.]+$/
if (!re.test(obj.value)) {
alert("璇疯緭鍏ラ樋鎷変集鏁板瓧");
obj.value = "";
}
}
function getHei() {
var fHeig = document.getElementById('wfhei').value;
if (fHeig == '') {
alert('璇疯緭鍏ョ埗浜茶韩楂�');
document.getElementById('wfhei').focus();
return false;
}
var mHeig = document.getElementById('wmhei').value;
if (mHeig == '') {
alert('璇疯緭鍏ユ瘝浜茶韩楂�');
document.getElementById('wmhei').focus();
return false;
}
var cSex = document.getElementById('wcsex1').checked;
if (!cSex && !document.getElementById('wcsex0').checked) {
alert('璇烽€夋嫨瀛愬コ鎬у埆');
return false;
}
if (cSex == true) {
var cHeig = (parseFloat(fHeig) + parseFloat(mHeig)) * 1.08 / 2;
} else {
var cHeig = (parseFloat(fHeig) * 0.923 + parseFloat(mHeig)) / 2;
}
document.getElementById('wtext').innerHTML = '鎮ㄥ疂瀹濈殑韬珮鍙兘鏄�<b class="red">'+cHeig.toFixed(1)+'</b> 鍘樼背(cm)';
document.getElementById('wresult').style.display = '';
var c = document.getElementById('wresult').innerHTML;
var i = '';
return {c:c, i:i};
}
function wInit() {
document.getElementById('wtext').innerHTML = '';
document.getElementById('wresult').style.display = 'none';
}
function handleWork(obj) {
var v = obj.value;
obj.disabled = true;
obj.value = '寮€濮嬭绠�';
// global callback
handleBegin();
var res = getHei();
if (typeof res == 'object' && res != null) {
// global callback
handleFinish(res.c, res.i);
}
obj.value = v;
obj.disabled = false;
}
显示效果:儿童身高计算器
参考文章:http://tishang.net/articles/1685455563.html