0

这是我在 id dlbtn 上触发点击事件时的 jquery 倒计时代码

var settimmer = 0;
$(function() {
    $('#dlbtn').click(function() {
        $('#dlnotify').toggle('slow');
        window.setInterval(function() {
            var timeCounter = $("b[id=show-time]").html();
            var updateTime = eval(timeCounter) - eval(1);
            $("b[id=show-time]").html(updateTime);
            if (updateTime <= 0) {
                window.location = ('/dl.php?fid=12');

                $('#dlnotify').hide();
            }
        }, 500);
        updateTime--;
        return false; //Kill the Event after request
    });

});​

我的脚本继续点击 dl.ph 页面

4

1 回答 1

0

我不是 100% 确定问题是什么,但是为了消除setInterval你需要打电话给clearInterval

http://www.w3schools.com/jsref/met_win_setinterval.asp

试试这个代码:

var settimmer = 0;
$(function() {
    $('#dlbtn').click(function() {
        $('#dlnotify').toggle('slow');
        settimmer =window.setInterval(function() {
            var timeCounter = $("b[id=show-time]").html();
            var updateTime = eval(timeCounter) - eval(1);
            $("b[id=show-time]").html(updateTime);
            if (updateTime <= 0) {

                window.location = ('/dl.php?fid=12');
                clearInterval(settimmer); // clear the interval to avoid multiple redirects 
                $('#dlnotify').hide();
            }
        }, 500);
        updateTime--;
        return false; //Kill the Event after request
    });

});​
于 2012-06-10T07:10:10.377 回答