如何执行相同的setInterval()

How to execute the same setInterval()

本文关键字:setInterval 执行 何执行      更新时间:2023-09-26

我的setInterval()有问题,我的代码是:

    var1=0;
function addNum(){
    var1++;
    $('.number').text(var1);
}

$(function() {
    $('.number').text(var1);
    jQuery('#box').on('touchstart touchmove', function(e) {
        mytimer = setInterval(function(){ addNum() }, 500);
    });
    jQuery('#box').on('touchend touchcancel', function(e) {
        alert('lift up');
        window.clearInterval(100);    
      });
    });

我无法清除Interval()下次如何使用相同的setInterval?

有人知道,如何重用它?

BR,Christian

将清除函数更改为window.clearInterval(mytimer);