所以我有这个倒计时代码:
countdowntime = '3'
var time_left = countdowntime;
var cinterval;
function time_dec(){
time_left--;
document.getElementById('countdown').innerHTML = time_left;
if(time_left == 0){
clearInterval(cinterval);alert('yes!');
}
}
cinterval = setInterval('time_dec()', 1000);
document.write('Time: <span id="countdown">', countdowntime ,'</span>');
我想使用countdowntime='3'
下面的代码:
var time_left = countdowntime;
var cinterval;
function time_dec(){
time_left--;
document.getElementById('countdown').innerHTML = time_left;
if(time_left == 0){
clearInterval(cinterval);alert('yes!');
}
}
cinterval = setInterval('time_dec()', 1000);
document.write('Time: <span id="countdown">', countdowntime ,'</span>');
countdowntime = '3'
但随后它停止工作!我试图通过使用函数和其他变量方式来修复它,但它没有起作用..请帮我解决它..