1,首先建一个截止日期的字段,截止日期输入表单替换html代码为:<input name="字段" id=jztime onkeyup="字段.value=字段.value.replace(/\,/g,',').replace(/\ /g,',');" type="text" size="" value="<?=stripSlashes($r[字段])?>">
主要是配合下面的js代码,方便后台输入,空格和中文都可自动换为“,”,这种方法也可用到关键词字段
2,列表页加上倒计时JS代码: <SCRIPT type="text/javascript"> <!-- var target=[] var time_id=[] function show_date_time_0(){ setTimeout("show_date_time_0()", 1000); for (var i=0,j=target.length;i<j;i++){ today=new Date(); timeold=target[i]-today.getTime(); sectimeold=timeold/1000; secondsold=Math.floor(sectimeold); msPerDay=24*60*60*1000; e_daysold=timeold/msPerDay; daysold=Math.floor(e_daysold); 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); if (daysold<0) { document.getElementById(time_id[i]).innerHTML="到期提示文字或者图片"; } else { if (daysold<10) {daysold="0"+daysold} if (daysold<100) {daysold="0"+daysold} if (hrsold<10) {hrsold="0"+hrsold} if (minsold<10) {minsold="0"+minsold} if (seconds<10) {seconds="0"+seconds} if (daysold<3) { document.getElementById(time_id[i]).innerHTML="<font color=red>"+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒</font>"; } else { document.getElementById(time_id[i]).innerHTML=daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒"; } } } } setTimeout("show_date_time_0()", 100); //--> </SCRIPT>
3,出现剩余天数的地方显示:<div id="TimeCounter_0" style="border:1px solid black;margin:5px;padding:2px;width:140px"></div> <SCRIPT> //设定目标时间(数组元素) //target[target.length]=new Date(年,月-1,日,时,分,秒).getTime() target[target.length]=new Date(2010,04,01,00,00,00).getTime(); //设定倒计时显示地址(数组元素) time_id[time_id.length]="TimeCounter_0" </SCRIPT>
例子:<li class="ynl2">[!--class.name--]</li> <li class="ynl3"><a title="[!--oldtitle--] " href="[!--titleurl--]" target="_blank" class="yl_06c"> [!--title--] </a></li> <li class="ynl4"> <div id="TimeCounter_[!--id--]"></div> <SCRIPT> target[target.length]=new Date([!--jztime--]).getTime(); time_id[time_id.length]="TimeCounter_[!--id--]" </SCRIPT> </li>
也可用到内容页上,这里显示的是年,月-1,日,时,分,秒,只想显示月和日期的把JS代码里相应值去掉即可:innerHTML=daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒
|