原来的代码有个缺点,过了日期之后,会显示负数:document.writeln("<!--done-->");
document.writeln("<div class=\"newsItem\">");
document.writeln("");
document.writeln("<span id=\"span_dt_dt\" style=\'align=center no:1px solid black;background-color:#FFFFFF\' ><\/span> ");
document.writeln("");
document.writeln("<SCRIPT language=javascript> ");
document.writeln("<!-- ");
document.writeln("\/\/document.write(\"\"); ");
document.writeln("");
document.writeln("function show_date_time(){ ");
document.writeln("window.setTimeout(\"show_date_time()\", 1000); ");
document.writeln("BirthDay=new Date(\"8-16-2010\");\/\/这个日期是可以修改的 ");
document.writeln("today=new Date(); ");
document.writeln("timeold=(BirthDay.getTime()-today.getTime()); ");
document.writeln("sectimeold=timeold\/1000 ");
document.writeln("secondsold=Math.floor(sectimeold); ");
document.writeln("msPerDay=24*60*60*1000 ");
document.writeln("e_daysold=timeold\/msPerDay ");
document.writeln("daysold=Math.floor(e_daysold); ");
document.writeln("e_hrsold=(e_daysold-daysold)*24; ");
document.writeln("hrsold=Math.floor(e_hrsold); ");
document.writeln("e_minsold=(e_hrsold-hrsold)*60; ");
document.writeln("minsold=Math.floor((e_hrsold-hrsold)*60); ");
document.writeln("seconds=Math.floor((e_minsold-minsold)*60); ");
document.writeln("span_dt_dt.innerHTML=\"<align=center><font color=red size=3><b>\"+daysold+\"<\/font></b>天<font color=red size=3><b>\"+hrsold+\"<\/font></b>小时<font color=red size=3><b>\"+minsold+\"<\/font></b>分<font color=red size=3><b>\"+seconds+\"<\/font></b>秒\"+\"<br>\" ; ");
document.writeln("");
document.writeln("} ");
document.writeln("");
document.writeln("show_date_time(); ");
document.writeln("");
document.writeln("\/\/--> ");
document.writeln("<\/SCRIPT>");
现改为就不行了,我是想实现到日期之后提示 已过期,谢谢关注。 请帮忙看看,,,谢谢。我修改后的:document.writeln("<!--done-->");
document.writeln("<div class=\"newsItem\">");
document.writeln("");
document.writeln("<span id=\"span_dt_dt\" style=\'align=center no:1px solid black;background-color:#FFFFFF\' ><\/span> ");
document.writeln("");
document.writeln("<SCRIPT language=javascript> ");
document.writeln("<!-- ");
document.writeln("\/\/document.write(\"\"); ");
document.writeln("");
document.writeln("function show_date_time(){ ");
document.writeln("window.setTimeout(\"show_date_time()\", 1000); ");
document.writeln("BirthDay=new Date(\"8-16-2010\");\/\/这个日期是可以修改的 ");
document.writeln("today=new Date(); ");
document.writeln("timeold=(BirthDay.getTime()-today.getTime()); ");
document.writeln("sectimeold=timeold\/1000 ");
document.writeln("secondsold=Math.floor(sectimeold); ");
document.writeln("msPerDay=24*60*60*1000 ");
document.writeln("e_daysold=timeold\/msPerDay ");
document.writeln("daysold=Math.floor(e_daysold); ");
document.writeln("if daysold>0 then;");
document.writeln("e_hrsold=(e_daysold-daysold)*24; ");
document.writeln("hrsold=Math.floor(e_hrsold); ");
document.writeln("e_minsold=(e_hrsold-hrsold)*60; ");
document.writeln("minsold=Math.floor((e_hrsold-hrsold)*60); ");
document.writeln("seconds=Math.floor((e_minsold-minsold)*60); ");
document.writeln("span_dt_dt.innerHTML=\"<align=center><font color=red size=3><b>\"+daysold+\"<\/font></b>天<font color=red size=3><b>\"+hrsold+\"<\/font></b>小时<font color=red size=3><b>\"+minsold+\"<\/font></b>分<font color=red size=3><b>\"+seconds+\"<\/font></b>秒\"+\"<br>\" ; ");
document.writeln("else;");
document.writeln("span_dt_dt.innerHTML=\"此次活动已结束 谢谢关注\"");
document.writeln("end if;");
document.writeln("} ");
document.writeln("");
document.writeln("show_date_time(); ");
document.writeln("");
document.writeln("\/\/--> ");
document.writeln("<\/SCRIPT>");
document.writeln("<div class=\"newsItem\">");
document.writeln("");
document.writeln("<span id=\"span_dt_dt\" style=\'align=center no:1px solid black;background-color:#FFFFFF\' ><\/span> ");
document.writeln("");
document.writeln("<SCRIPT language=javascript> ");
document.writeln("<!-- ");
document.writeln("\/\/document.write(\"\"); ");
document.writeln("");
document.writeln("function show_date_time(){ ");
document.writeln("window.setTimeout(\"show_date_time()\", 1000); ");
document.writeln("BirthDay=new Date(\"8-16-2010\");\/\/这个日期是可以修改的 ");
document.writeln("today=new Date(); ");
document.writeln("timeold=(BirthDay.getTime()-today.getTime()); ");
document.writeln("sectimeold=timeold\/1000 ");
document.writeln("secondsold=Math.floor(sectimeold); ");
document.writeln("msPerDay=24*60*60*1000 ");
document.writeln("e_daysold=timeold\/msPerDay ");
document.writeln("daysold=Math.floor(e_daysold); ");
document.writeln("e_hrsold=(e_daysold-daysold)*24; ");
document.writeln("hrsold=Math.floor(e_hrsold); ");
document.writeln("e_minsold=(e_hrsold-hrsold)*60; ");
document.writeln("minsold=Math.floor((e_hrsold-hrsold)*60); ");
document.writeln("seconds=Math.floor((e_minsold-minsold)*60); ");
document.writeln("span_dt_dt.innerHTML=\"<align=center><font color=red size=3><b>\"+daysold+\"<\/font></b>天<font color=red size=3><b>\"+hrsold+\"<\/font></b>小时<font color=red size=3><b>\"+minsold+\"<\/font></b>分<font color=red size=3><b>\"+seconds+\"<\/font></b>秒\"+\"<br>\" ; ");
document.writeln("");
document.writeln("} ");
document.writeln("");
document.writeln("show_date_time(); ");
document.writeln("");
document.writeln("\/\/--> ");
document.writeln("<\/SCRIPT>");
现改为就不行了,我是想实现到日期之后提示 已过期,谢谢关注。 请帮忙看看,,,谢谢。我修改后的:document.writeln("<!--done-->");
document.writeln("<div class=\"newsItem\">");
document.writeln("");
document.writeln("<span id=\"span_dt_dt\" style=\'align=center no:1px solid black;background-color:#FFFFFF\' ><\/span> ");
document.writeln("");
document.writeln("<SCRIPT language=javascript> ");
document.writeln("<!-- ");
document.writeln("\/\/document.write(\"\"); ");
document.writeln("");
document.writeln("function show_date_time(){ ");
document.writeln("window.setTimeout(\"show_date_time()\", 1000); ");
document.writeln("BirthDay=new Date(\"8-16-2010\");\/\/这个日期是可以修改的 ");
document.writeln("today=new Date(); ");
document.writeln("timeold=(BirthDay.getTime()-today.getTime()); ");
document.writeln("sectimeold=timeold\/1000 ");
document.writeln("secondsold=Math.floor(sectimeold); ");
document.writeln("msPerDay=24*60*60*1000 ");
document.writeln("e_daysold=timeold\/msPerDay ");
document.writeln("daysold=Math.floor(e_daysold); ");
document.writeln("if daysold>0 then;");
document.writeln("e_hrsold=(e_daysold-daysold)*24; ");
document.writeln("hrsold=Math.floor(e_hrsold); ");
document.writeln("e_minsold=(e_hrsold-hrsold)*60; ");
document.writeln("minsold=Math.floor((e_hrsold-hrsold)*60); ");
document.writeln("seconds=Math.floor((e_minsold-minsold)*60); ");
document.writeln("span_dt_dt.innerHTML=\"<align=center><font color=red size=3><b>\"+daysold+\"<\/font></b>天<font color=red size=3><b>\"+hrsold+\"<\/font></b>小时<font color=red size=3><b>\"+minsold+\"<\/font></b>分<font color=red size=3><b>\"+seconds+\"<\/font></b>秒\"+\"<br>\" ; ");
document.writeln("else;");
document.writeln("span_dt_dt.innerHTML=\"此次活动已结束 谢谢关注\"");
document.writeln("end if;");
document.writeln("} ");
document.writeln("");
document.writeln("show_date_time(); ");
document.writeln("");
document.writeln("\/\/--> ");
document.writeln("<\/SCRIPT>");
<!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>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="[email protected]" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>
<body>
<!--done-->
<div class="newsItem">
<span id="span_dt_dt" style='align=center no:1px solid black;background-color:#FFFFFF' ></span> <SCRIPT language=javascript>
<!--
var iTimerID = window.setInterval(show_date_time, 1000);function show_date_time(){
BirthDay=new Date(2010,7,16,13,47,0);//这个日期是可以修改的
today=new Date();
timeold=(BirthDay.getTime()-today.getTime());
sectimeold=timeold/1000;
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000;
e_daysold=timeold/msPerDay;
daysold=Math.floor(e_daysold);
if (secondsold>0) {
e_hrsold=(e_daysold-daysold)*24;
hrsold=Math.floor(e_hrsold);
e_minsold=(e_hrsold-hrsold)*60;
minsold=Math.floor((e_hrsold-hrsold)*60);
seconds=Math.floor((e_minsold-minsold)*60);
span_dt_dt.innerHTML="<align=center><font color=red size=3><b>"+daysold+"</font></b>天<font color=red size=3><b>"+hrsold+"</font></b>小时<font color=red size=3><b>"+minsold+"</font></b>分<font color=red size=3><b>"+seconds+"</font></b>秒"+"<br>" ;
}
else {
window.clearInterval(iTimerID);
span_dt_dt.innerHTML = "此次活动已结束 谢谢关注";
}
} //-->
</SCRIPT>
</body>
</html>
Web 开发常用手册DHTML 参考手册
http://download.csdn.net/source/308913JScript 语言参考
http://download.csdn.net/source/308916CCS 样式表中文手册
http://download.csdn.net/source/304124