高分跪求求一个循环倒计时的JS代码,网页上用的。
<spanid="span_dt_dt"></span><scriptlanguage=javascript>functionshow_date_time(){windo...
<span id="span_dt_dt"></span>
<script language=javascript>
function show_date_time(){
window.setTimeout("show_date_time()", 1000);
BirthDay=new Date("02/26/2012");//改成你的计时日期
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);
e_hrsold=(e_daysold-daysold)*24;
hrsold=Math.floor(e_hrsold);
if (hrsold < 10){
hrsold = "0"+hrsold;
}
e_minsold=(e_hrsold-hrsold)*60;
minsold=Math.floor((e_hrsold-hrsold)*60);
if (minsold < 10){
minsold = "0"+minsold;
}
seconds=Math.floor((e_minsold-minsold)*60);
if (seconds < 10){
seconds = "0"+seconds;
}
document.getElementById("span_dt_dt").innerHTML=daysold+"<b>D</b>"+hrsold+"<b>H</b>"+minsold+"<b>M</b>"+seconds+"<b>S</b>";
}
show_date_time();
</script>
目前的代码是倒计时,我想在倒计时到0后,计时日期自动延长3天,并以此时间循环倒计时。反复循环。 展开
<script language=javascript>
function show_date_time(){
window.setTimeout("show_date_time()", 1000);
BirthDay=new Date("02/26/2012");//改成你的计时日期
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);
e_hrsold=(e_daysold-daysold)*24;
hrsold=Math.floor(e_hrsold);
if (hrsold < 10){
hrsold = "0"+hrsold;
}
e_minsold=(e_hrsold-hrsold)*60;
minsold=Math.floor((e_hrsold-hrsold)*60);
if (minsold < 10){
minsold = "0"+minsold;
}
seconds=Math.floor((e_minsold-minsold)*60);
if (seconds < 10){
seconds = "0"+seconds;
}
document.getElementById("span_dt_dt").innerHTML=daysold+"<b>D</b>"+hrsold+"<b>H</b>"+minsold+"<b>M</b>"+seconds+"<b>S</b>";
}
show_date_time();
</script>
目前的代码是倒计时,我想在倒计时到0后,计时日期自动延长3天,并以此时间循环倒计时。反复循环。 展开
1个回答
展开全部
<span id="span_dt_dt"></span>
<script language=javascript>
var daytemp=3//新增加变量
function show_date_time(){
window.setTimeout("show_date_time()", 1000);
BirthDay=new Date("02/26/2012");//改成你的计时日期
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);
e_hrsold=(e_daysold-daysold)*24;
hrsold=Math.floor(e_hrsold);
if (hrsold < 10){
hrsold = "0"+hrsold;
}
e_minsold=(e_hrsold-hrsold)*60;
minsold=Math.floor((e_hrsold-hrsold)*60);
if (minsold < 10){
minsold = "0"+minsold;
}
seconds=Math.floor((e_minsold-minsold)*60);
if (seconds < 10){
seconds = "0"+seconds;
}
//以下为增加代码:希望你测试通过,然后给分
if(daysold>=0)
{
document.getElementById("span_dt_dt").innerHTML=daysold+"<b>D</b>"+hrsold+"<b>H</b>"+minsold+"<b>M</b>"+seconds+"<b>S</b>";
}
else
{
if(daysold+daytemp>=0)
{
document.getElementById("span_dt_dt").innerHTML=(daysold+daytemp)+"<b>D</b>"+hrsold+"<b>H</b>"+minsold+"<b>M</b>"+seconds+"<b>S</b>";
}
else
{
daytemp=daytemp+3;
}
}
}
show_date_time();
</script>
<script language=javascript>
var daytemp=3//新增加变量
function show_date_time(){
window.setTimeout("show_date_time()", 1000);
BirthDay=new Date("02/26/2012");//改成你的计时日期
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);
e_hrsold=(e_daysold-daysold)*24;
hrsold=Math.floor(e_hrsold);
if (hrsold < 10){
hrsold = "0"+hrsold;
}
e_minsold=(e_hrsold-hrsold)*60;
minsold=Math.floor((e_hrsold-hrsold)*60);
if (minsold < 10){
minsold = "0"+minsold;
}
seconds=Math.floor((e_minsold-minsold)*60);
if (seconds < 10){
seconds = "0"+seconds;
}
//以下为增加代码:希望你测试通过,然后给分
if(daysold>=0)
{
document.getElementById("span_dt_dt").innerHTML=daysold+"<b>D</b>"+hrsold+"<b>H</b>"+minsold+"<b>M</b>"+seconds+"<b>S</b>";
}
else
{
if(daysold+daytemp>=0)
{
document.getElementById("span_dt_dt").innerHTML=(daysold+daytemp)+"<b>D</b>"+hrsold+"<b>H</b>"+minsold+"<b>M</b>"+seconds+"<b>S</b>";
}
else
{
daytemp=daytemp+3;
}
}
}
show_date_time();
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询