1
這裏是功能只需點擊btnGo計時器將停止並獲得它的價值,如果剩餘時間不超過其自動添加+1到時間總計我的問題是它不添加它只顯示下面的值是我的代碼與現場演示jQuery計數與計時器
我的JS
var sec = $('#timerSec').text() || 0;
var timer;
function startTimer() {
if (timer) clearInterval(timer);
sec = 10;
timer = setInterval(function() {
$('#timerSec').text(sec--);
if (sec == 0) {
clearInterval(timer);
}
}, 1000);
}
$(function() {
startTimer();
$('#btnGo').click(function(){
$(this).fadeOut();
$("#alert").fadeIn();
clearInterval(timer);
var secR = $('#timerSec').text();
var t = $('#alert span').text()
$('#btnCon').fadeIn();
if (secR != 0){
var i = t+1;
}
$('#alert span').html(i).show();
});
$('#btnCon').click(function(){
$("#alert").fadeOut();
$("#btnGo").fadeIn();
startTimer();
});
});
我的HTML
<div id="timerSec">10</div> seconds
<a href="#" id="btnGo">Go</a>
<div id="alert" style="display:none">
<a href="#" id="btnCon" >Continue</a>
On time = <span>0</span>
</div>
Live Demo的jsfiddle
另一個添加的學習感謝哥們!它完美的作品 – noviceRick
沒問題:)高興地幫助。 –