所以,我的問題是,我想讓我的倒計時清除,當我點擊'後退'圖標。這是如此,如果用戶點擊返回到計時器頁面,它將被重置,而不是從他們回擊時繼續。當我按'home'按鈕時,我正試圖清除我的倒計時
這是代碼,我認爲應該做的伎倆行:
$('.ui-icon-back').click (clearInterval(countdown));
這裏是我的HTML:
<!-- /////////////////
Green Tea
////////////////////// -->
<!--Create section tag-->
<section data-role="page" id="green">
<!--Create header tag-->
<header data-role="header">
<!--Create h1 tag-->
<h1> TEA TIME </h1>
<!--Create a icon that will link back to the home page-->
<a href="#home" class="ui-btn ui-btn-icon-top ui-icon-back ui-btn-icon-notext">back</a>
<!--End header-->
</header>
<!--Create h1 tag that states full steep time-->
<h1>Green Tea Takes 2 Minutes</h1>
<!--Show timer duration before timer start-->
<p id="timedisp">120 sec</p>
<!--Call the countdown-->
<div class="clock">
</div>
<!-- Button to trigger the start timer js-->
<a href="#" id="start">Start</a>
<!-- Button to trigger the timer restart-->
<a href="#" id="reset">Reset</a>
<!-- End section tag-->
</section>
這裏是我的javascript:
// JavaScript Document
//Green Tea Timer
function greenTea(){
// Set The Duration
var duration = 120;
// Insert the duration into the div with a class of clock
$(".clock").html(duration + " sec");
// Create a countdown interval
var countdown = setInterval(function (greenTea) {
// subtract one from duration and test to see
// if duration is still above zero
if (--duration) {
// Update the clocks's message
$(".clock").html(duration + " sec");
// Otherwise
} else {
// Clear the countdown interval
clearInterval(countdown);
// set a completed message
$(".clock").html("End Your Steep");
}
// Run interval every 1000ms
}, 1000);
};
$("a#start").click(greenTea);
$('#start').click(function(greenTea){
$('#timedisp').hide();
});
$('#reset').click(function(greenTea) {
location.reload();
});
$('.ui-icon-back').click (clearInterval(countdown));
你還好嗎或者是它只是週日晚上踢? :)你試過'$('。ui-icon-back')。click(function(){clearInterval(countdown)});' – lshettyl