js计算孕期天数的代码

js计算孕期天数的方法,js计算孕期天数的代码教程如下:

1.输入平均月经周期

2.输入末次月经时间

实现结果:孕期周数

js实现代码如下:

function yunchan() {
var year = document.getElementById('wyear');
var month = document.getElementById('wmonth');
var day = document.getElementById('wday');
if (year.value == "" || month.value == "" || day.value == "") {
alert("璇峰~鍐欏畬鏁村勾鏈堟棩!");
return;
}
if (year.value > 2050 || year.value < 1990) {
alert("璇峰~鍐欐纭勾浠�!");
year.focus();
return;
}
if (month.value > 12 || month.value < 1) {
alert("璇峰~鍐欐纭湀浠�!");
month.focus();
return;
}
if (day.value > 31 || day.value < 1) {
alert("璇峰~鍐欐纭棩瀛�!");
day.focus();
return;
}
if (!isDate(year.value, month.value, day.value)) {
alert("骞存湀鏃ョ粍鍚堟湁閿�,璇烽噸鏂板~鍐�!");
return;
}

function isDate(year, month, day) {
// month argument must be in the range 1 - 12
month = month - 1; // javascript month range : 0- 11
var tempDate = new Date(year, month, day);
if ((year2k(tempDate.getFullYear()) == year) && (month == tempDate.getMonth()) && (day == tempDate.getDate())) {
return true;
} else {
return;
}
}

function year2k(d) {
return (d < 1000) ? d + 1900 : d;
}

var stime = new Date();
stime.setFullYear(year.value);
stime.setMonth(month.value - 1);
stime.setDate(day.value);

var yue = document.getElementById('wperiod').value;
var true_number = 280;
if (yue < 28) {
true_number = 280 - (28 - yue);
} else if (yue > 28) {
true_number = 280 + (yue - 28);
} else if (yue == 28) {
true_number = 280;
}

if (yue.value != '') {
var temptime = stime.getTime();
stime.setTime((stime.getTime() + true_number * 24 * 3600 * 1000))
var yuchan = stime.getFullYear() + "-" + (stime.getMonth() + 1) + "-" + stime.getDate();
var nowt = new Date();
var chatime = nowt.getTime() - temptime;
var chaweek = Math.floor((chatime) / (1000 * 60 * 60 * 24 * 7));
var chaweek_1 = Math.floor((chatime) / (1000 * 60 * 60 * 24));
if (chaweek < 0) chaweek = 0;
if (chaweek_1 > (true_number + 14)) {
alert("浣犵殑棰勪骇鏈熷凡杩�!");
return null;
}
document.getElementById('wtext').innerHTML = '鎮ㄧ殑棰勪骇鏈熸槸 <b class="red">'+yuchan+'</b>锛涚幇鍦ㄦ澶勪簬瀛曟湡鐨勭 <b class="red">'+chaweek+'</b> 鍛�';
document.getElementById('wresult').style.display = '';

var c = document.getElementById('wresult').innerHTML;
var i = '';
return {c:c, i:i};
} else {
return null;
}

}

function wInit() {
document.getElementById('wresult').style.display = 'none';
var d = new Date();
d.setMonth(d.getMonth() - 8);
document.getElementById('wyear').value = d.getFullYear();
document.getElementById('wmonth').value = d.getMonth() + 1;
document.getElementById('wday').value = d.getDate();
document.getElementById('wyear').onclick = function(event) {WdatePicker({dateFmt:'yyyy',minDate:'1901', maxDate:'2050'})};
document.getElementById('wmonth').onclick = function(event) {WdatePicker({dateFmt:'M'})};
document.getElementById('wday').onclick = function(event) {WdatePicker({dateFmt:'d'})};
var p = document.getElementById('wperiod');
for (var i = 20; i <= 45; i++) {
p.options.add(new Option(i + '澶�', i));
}
p.options[8].selected = true;
}

function handleWork(obj) {
var v = obj.value;
obj.disabled = true;
obj.value = '寮€濮嬭绠�';

// global callback
handleBegin();

var res = yunchan();

if (typeof res == 'object' && res != null) {
// global callback
handleFinish(res.c, res.i);
}

obj.value = v;
obj.disabled = false;
}

显示效果:孕期计算器

参考文章:http://tishang.net/articles/1685881312.html 

快乐下载

软件屋下载

中元手游网

铁盒下载

孕期计算器

bmi指数计算器

日期计算器

排卵日期计算器

条形码生成器

油耗计算器

posted @ 2023-06-04 20:27  kaiser099  阅读(13)  评论(0编辑  收藏  举报