找回密码
 注册
搜索
热搜: java php web
查看: 199|回复: 2

[未解决] 求助一个计算出生时间的JavaScript注释

[复制链接]
发表于 2009-12-27 19:57:02 | 显示全部楼层 |阅读模式
<html>
<head>
<title>网页特效---计算出生时间</title>
<style type="text/css">
<!--
body {  font-family: "宋体"; font-size: 9pt; margin-top: 0px; margin-left: 4px; margin-right: 0px}
A { COLOR: black; FONT-SIZE: 13px; FONT-WEIGHT: 400; TEXT-DECORATION: none }
A:hover { COLOR: red; FONT-SIZE: 13px; FONT-WEIGHT: 400; TEXT-DECORATION: underline }
a:active     { font: 9pt "宋体"; cursor: hand; color: #FF0033 }
--></style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>   
<br>  
<br>
<center><font color=red face="隶书" size=6>计算出生时间</font></center>
<br>
<center>
<table border=0 bordercolor=blue borderlight=green style="border-collapse: collapse" cellpadding="0" cellspacing="0">
<tr><td align=center height=80>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var mm = prompt('请输入你出生的月份?','1-12');   
var bday = prompt('请输入你出生在哪一天?','1-31');  
var byear = prompt('请输入你出生的年份?','1975');  
var year = new Date();      
var year2 = year.getYear();      
var year3 = (year < 2000) ? year2 + 1900 : year2;  
thedate = new Date();      
mm2 = thedate.getMonth() + 1;      
dd2 = thedate.getDate();      
yy2 = thedate.getYear();      
if (yy2 < 100) yy2 += 1900      
yourage = yy2 - byear;
if (mm2 < mm) yourage--;
if ((mm2 == mm) && (dd2 < bday)) yourage--;
TMonth = new Array(      
'January','February','March',
'April','May','June','July',
'August','September','October',
'November','December'
);
CurMonth = mm - 1;      
bmonth = TMonth[CurMonth];      
var age2 = yourage + 1;
var timerID;
var timerRunning = false;
var today = new Date();
var startday = new Date();
var enday = new Date();
var secPerDay = 0;
var minPerDay = 0;
var hourPerDay = 0;
var secsLeft = 0;
var secsRound = 0;
var secsRemain = 0;
var minLeft = 0;
var minRound = 0;
var minRemain = 0;
var timeRemain = 0;
function stopclock() {
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function startclock() {
stopclock();
showtime();
showtime1();
}
function showtime() {
today = new Date();
enday = new Date(""+bmonth+", "+bday+" "+year3+" 00:00");
enday.setYear(""+year3+"");
secsPerDay = 1000 ;
minPerDay = 60 * 1000 ;
hoursPerDay = 60 * 60 * 1000;
PerDay = 24 * 60 * 60 * 1000;
secsLeft = (enday.getTime() - today.getTime()) / minPerDay;
secsRound = Math.round(secsLeft);
secsRemain = secsLeft - secsRound;
secsRemain = (secsRemain < 0) ? secsRemain = 60 - ((secsRound - secsLeft) * 60) : secsRemain = (secsLeft - secsRound) * 60;
secsRemain = Math.round(secsRemain);
minLeft = ((enday.getTime() - today.getTime()) / hoursPerDay);
minRound = Math.round(minLeft);
minRemain = minLeft - minRound;
minRemain = (minRemain < 0) ? minRemain = 60 - ((minRound - minLeft)  * 60) : minRemain = ((minLeft - minRound) * 60);
minRemain = Math.round(minRemain - 0.495);
hoursLeft = ((enday.getTime() - today.getTime()) / PerDay);
hoursRound = Math.round(hoursLeft);
hoursRemain = hoursLeft - hoursRound;
hoursRemain = (hoursRemain < 0) ? hoursRemain = 24 - ((hoursRound - hoursLeft)  * 24) : hoursRemain = ((hoursLeft - hoursRound) * 24);
hoursRemain = Math.round(hoursRemain - 0.5);
daysLeft = ((enday.getTime() - today.getTime()) / PerDay);
daysLeft = (daysLeft - 0.5);
daysRound = Math.round(daysLeft);
daysRemain = daysRound;
if (daysRemain == 1) day_rem = " day, "
else day_rem = " 天, "
if (hoursRemain == 1) hour_rem = " hour, "
else hour_rem = " 小时, "
if (minRemain == 1) min_rem = " minute, "
else min_rem = " 分, "
if (secsRemain == 1) sec_rem = " second"
else sec_rem = " 秒"
timeRemain = daysRemain + day_rem + hoursRemain + hour_rem + minRemain + min_rem + secsRemain + sec_rem;
document.down.face.value = timeRemain;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
if (daysRemain < 0) year3 = year3 + 1
}
function showtime1() {
startday = new Date(""+bmonth+" "+bday+", "+byear+" 00:00 EDT");
startday.setYear(""+byear+"");
today = new Date();
secsPerDay = 1000 ;
minPerDay = 60 * 1000 ;
hoursPerDay = 60 * 60 * 1000;
PerDay = 24 * 60 * 60 * 1000;
secsLeft = (today.getTime() - startday.getTime()) / minPerDay;
secsRound = Math.round(secsLeft);
secsRemain = secsLeft - secsRound;
secsRemain = (secsRemain < 0) ? secsRemain = 60 - ((secsRound - secsLeft) * 60) : secsRemain = (secsLeft - secsRound) * 60;
secsRemain = Math.round(secsRemain);
minLeft = ((today.getTime() - startday.getTime()) / hoursPerDay);
minRound = Math.round(minLeft);
minRemain = minLeft - minRound;
minRemain = (minRemain < 0) ? minRemain = 60 - ((minRound - minLeft) * 60) : minRemain = ((minLeft - minRound) * 60);
minRemain = Math.round(minRemain - 0.495);
hoursLeft = ((today.getTime() - startday.getTime()) / PerDay);
hoursRound = Math.round(hoursLeft);
hoursRemain = hoursLeft - hoursRound;
hoursRemain = (hoursRemain < 0) ? hoursRemain = 24 - ((hoursRound - hoursLeft) * 24)  : hoursRemain = ((hoursLeft - hoursRound) * 24);
hoursRemain = Math.round(hoursRemain - 0.5);
daysLeft = ((today.getTime() - startday.getTime()) / PerDay);
daysLeft = (daysLeft - 0.5);
daysRound = Math.round(daysLeft);
daysRemain = daysRound;
if (daysRemain == 1) day_rem = " day, "
else day_rem = " 天, "
if (hoursRemain == 1) hour_rem = " hour, "
else hour_rem = " 小时, "
if (minRemain == 1) min_rem = " minute, "
else min_rem = " 分, "
if (secsRemain == 1) sec_rem = " second"
else sec_rem = " 秒"
timeRemain = daysRemain + day_rem + hoursRemain + hour_rem + minRemain + min_rem + secsRemain + sec_rem;
document.up.face.value = timeRemain;
timerID = setTimeout("showtime1()",1000);
timerRunning = true;
}
//  End -->
</script>
<form name="down">
<script Language="JavaScript">
document.write("<b>你出生于"+bmonth+" "+bday+", "+byear+".  ("+mm+"/"+bday+"/"+byear+")</b>");
document.write("<br><br>你已经 "+yourage+" 岁了,离你生日还有.");
</script>
<br>
<input type="text" name="face" size="47" value="A browser supporting JavaScript 1.1+ is needed.">
</form>
<p>
<br>
<form name="up">
你已经生活了...<br>
<input type="text" name="face" size="47" value="A browser supporting JavaScript 1.1+ is needed.">
</form>
</td></tr></table></center>
<br>
<br>
<center>
<SCRIPT LANGUAGE="JavaScript">
<!-- hide
function goHist(a)
{
   history.go(a);
}
//-->
</script>
</center>
<br>
<center>
&nbsp;<br>
<br>
</body>
</html>
发表于 2009-12-28 22:09:51 | 显示全部楼层
只能在IE上run
firefox3.5.6不能run...

评分

1

查看全部评分

回复

使用道具 举报

发表于 2010-1-6 17:04:47 | 显示全部楼层
这个主要是你些的js的兼容性问题了。js的函数并不是在所有浏览器中都可以用的。有些浏览器支持,有些不支持。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|软晨网(RuanChen.com)

GMT+8, 2024-11-25 14:46

Powered by Discuz! X3.5

Copyright © 2001-2023 Tencent Cloud.

快速回复 返回顶部 返回列表