JS倒计时页面代码(要求读取服务器时间)

JS倒计时页面代码(要求读取服务器时间),第1张

<script language="JavaScript">
function setTab(name,cursel,n){
for(i=1;i<=n;i++){
var menu=documentgetElementById(name+i);
var con=documentgetElementById("con_"+name+"_"+i);
menuclassName=i==cursel"hover":"";
constyledisplay=i==cursel"block":"none";
}
}var DifferenceHour = -1
var DifferenceMinute = -1
var DifferenceSecond = -1
var Tday = new Date("Feb 14, 2010 00:00:00") //倒计时时间点-注意格式
var daysms = 24 60 60 1000
var hoursms = 60 60 1000
var Secondms = 60 1000
var microsecond = 1000function left(mainStr,lngLen) {
if (lngLen>0) {return mainStrsubstring(0,lngLen)}
else{return null}
}
function right(mainStr,lngLen) { if (mainStrlength-lngLen>=0 && mainStrlength>=0 && mainStrlength-lngLen<=mainStrlength) {
return mainStrsubstring(mainStrlength-lngLen,mainStrlength)}
else{return null}
}
function mid(mainStr,starnum,endnum){
if (mainStrlength>=0){
return mainStrsubstr(starnum,endnum)
}else{return null} }function clock()
{
var time = new Date()
var hour = timegetHours()
var minute = timegetMinutes()
var second = timegetSeconds()
var timevalue = ""+((hour > 12) hour-12:hour)
timevalue +=((minute < 10) ":0":":")+minute
timevalue +=((second < 10) ":0":":")+second
timevalue +=((hour >12 ) " PM":" AM")var convertHour = DifferenceHour
var convertMinute = DifferenceMinute
var convertSecond = DifferenceSecond
var Diffms = TdaygetTime() - timegetTime()
DifferenceHour = Mathfloor(Diffms / daysms)
Diffms -= DifferenceHour daysms
DifferenceMinute = Mathfloor(Diffms / hoursms)
Diffms -= DifferenceMinute hoursms
DifferenceSecond = Mathfloor(Diffms / Secondms)
Diffms -= DifferenceSecond Secondms
var dSecs = Mathfloor(Diffms / microsecond)var dd=documentgetElementById("dd");
var hh=documentgetElementById("hh");
var mm=documentgetElementById("mm");
var ss=documentgetElementById("ss");ddstr = DifferenceHourtoString();
hhstr = DifferenceMinutetoString();
mmstr = DifferenceSecondtoString();
ssstr = dSecstoString();if (TdaygetTime() > timegetTime()){
if (ddstrlength<2){
ddstrs = "<span class='num0'></span><span class='num"+ddstrsubstr(0,1)+"'></span>";
}else{
ddstrs = "<span class='num"+ddstrsubstr(0,1)+"'></span><span class='num"+ddstrsubstr(1,2)+"'></span>";
}if (hhstrlength<2){
hhstrs = "<span class='num0'></span><span class='num"+hhstrsubstr(0,1)+"'></span>";
}else{
hhstrs = "<span class='num"+hhstrsubstr(0,1)+"'></span><span class='num"+hhstrsubstr(1,2)+"'></span>";
}if (mmstrlength<2){
mmstrs = "<span class='num0'></span><span class='num"+mmstrsubstr(0,1)+"'></span>";
}else{
mmstrs = "<span class='num"+mmstrsubstr(0,1)+"'></span><span class='num"+mmstrsubstr(1,2)+"'></span>";
}if (ssstrlength<2){
ssstrs = "<span class='num0'></span><span class='num"+mmstrsubstr(0,1)+"'></span>";
}else{
ssstrs = "<span class='num"+ssstrsubstr(0,1)+"'></span><span class='num"+ssstrsubstr(1,2)+"'></span>";
}
}else{
ddstrs="<span class='num0'></span><span class='num0'></span>"
hhstrs="<span class='num0'></span><span class='num0'></span>"
mmstrs="<span class='num0'></span><span class='num0'></span>"
ssstrs="<span class='num0'></span><span class='num0'></span>"
}if(convertHour != DifferenceHour) ddinnerHTML=ddstrs;
if(convertMinute != DifferenceMinute) hhinnerHTML=hhstrs;
if(convertSecond != DifferenceSecond) mminnerHTML=mmstrs;
ssinnerHTML=ssstrs;
setTimeout("clock()",1000)}</script> 上面的是JS部分的。 下面是HTML部分的。<div class="mains">
<div class="djs">
<div id="dd"></div>
<div id="tsfm">天</div>
<div id="hh"></div>
<div id="tsfm">时</div>
<div id="mm"></div>
<div id="tsfm">分</div>
<div id="ss"></div>
<div id="tsfm">秒</div>
</div> 我上面的JS部分的数字全部是用的格式显示倒计时数字的哈,你也可以自己改成数字。 好了,上面的代码全部是我之前给客户写的一个春节倒计时贺卡的程序页面,纯原创,并且一直在用,所以是没有任何问题的,你自己应该懂一些技术吧,所以上面的代码你应该看的懂,很简单的。 就不要再追问了,自己多下下功夫研究下,因为最近比较忙,不见得有时间回复,见谅。记得给我分哈,要升级这个号的级别,以后好推广用,谢谢了。

1、直接在src中输出;
<script src= "<php echo base_url();>resource/aaajs"></script>
2、借用base标签;
将base_url()的输出放在< base href = "<php echo base_url();>"/>标签里面,这样在页面里面调用比较方便,如下:
< base href = "<php echo base_url();>"/>
<script src= "resource/aaajs"></script>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10730686.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-10
下一篇 2023-05-10

发表评论

登录后才能评论

评论列表(0条)

保存