簡體   English   中英

如果在單擊jquery事件中,clearInterval不起作用?

[英]clearInterval doesn't work if is in click jquery event?

我想使用clearInterval但我不知道為什么不起作用。

var orologio_real;  //global variable 

$(document).ready(function(){
    orologio(1);

    $('#change-time').on('click', function(){
        clearInterval(orologio_real);   
        orologio(0);
    });
});

function orologio (arg){
    orologio_real= setInterval(function(){
    alert(arg)
    }, 1000);
}

我不明白的是為什么我單擊div時clearInterval無法正常工作

我認為這是一個愚蠢的錯誤。 您將在點擊處理程序中重新設置時間間隔。 我將其注釋掉,並增加了間隔,以便您有時間單擊按鈕

var orologio_real;  //global variable 

$(document).ready(function(){
    orologio(1);

    $('#change-time').on('click', function(){
        clearInterval(orologio_real);   
        //orologio(0); //this was the issue
    });
});

function orologio (arg){
    orologio_real= setInterval(function(){
    console.log(arg);
    alert(arg);
    }, 3000);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM