这段代码是写在C#中的页面cs代码中的
Itemtemp += "<td>剩余时间:<span id=\"LiveClock1\"> </span> \r\n";
//按有效期
Itemtemp += "<script language=\"javascript\"> \r\n";
Itemtemp += "<!-- \r\n";
Itemtemp += "function DigitalTime1() \r\n";
Itemtemp += "{ \r\n";
Itemtemp += "var deadline= new Date(\"" + DateTime.Parse(dt.Rows[0]["dtValidDate"].ToString()).ToString("yyyy/MM/dd HH:mm:ss",
DateTimeFormatInfo.InvariantInfo) + "\") \r\n"; //把C#代码中取时间
Itemtemp += "var symbol=\"\" \r\n";
Itemtemp += "var now = new Date() \r\n";
Itemtemp += "var diff = -480 - now.getTimezoneOffset() //是北京时间和当地时间的时间差 \r\n";
Itemtemp += "var leave = (deadline.getTime() - now.getTime()) + diff*60000 \r\n";
Itemtemp += "var leave = (deadline.getTime() - now.getTime()) \r\n";
Itemtemp += "var day = Math.floor(leave / (1000 * 60 * 60 * 24)) \r\n";
Itemtemp += "var hour = Math.floor(leave / (1000*3600)) - (day * 24) \r\n";
Itemtemp += "var minute = Math.floor(leave / (1000*60)) - (day * 24 *60) - (hour * 60) \r\n";
Itemtemp += "var second = Math.floor(leave / (1000)) - (day * 24 *60*60) - (hour * 60 * 60) - (minute*60) \r\n";
Itemtemp += "var LiveClock1=document.getElementById(\"LiveClock1\") \r\n";
Itemtemp += "day=day; \r\n";
Itemtemp += "if (day>0) \r\n"; //天数大于0
Itemtemp += "{ \r\n";
Itemtemp += "LiveClock1.innerHTML = \"\"+symbol+\"\"+day+\"天\"+hour+\"小时\"+minute+\"分\"+second +\"秒\" \r\n";
Itemtemp += "setTimeout(\"DigitalTime1()\",1000) \r\n";
Itemtemp += "} \r\n";
Itemtemp += "if (day<=0) \r\n"; //天数小于0
Itemtemp += "{ \r\n";
Itemtemp += "LiveClock1.innerHTML = \"\"+symbol+\"\"+hour+\"小时\"+minute+\"分\"+second +\"秒\" \r\n";
Itemtemp += "setTimeout(\"DigitalTime1()\",1000) \r\n";
Itemtemp += "} \r\n";
Itemtemp += "if (day<=0 & hour<=0 & minute<=0 & second<=0) \r\n"; //已结束
Itemtemp += "{ \r\n";
Itemtemp += "LiveClock1.innerHTML = \"已结束\" \r\n";
Itemtemp += "setTimeout(\"DigitalTime1()\",1000) \r\n";
Itemtemp += "} \r\n";
Itemtemp += "} \r\n";
Itemtemp += "DigitalTime1() \r\n";
Itemtemp += "// --> \r\n";
Itemtemp += "</script> \r\n";
C#(asp.net)中用javascript实现倒计时代码讲解完,如有疑问,也可以到25亿企业网站管理系统技术社区的网站建设栏目处提问。
作者: SEO技术@ 企业网站管理系统
原载: 25亿企业网站管理系统
版权所有。转载时必须以链接形式注明作者和原始出处及本声明。