I have a button which triggers the function inside set interval every 1 sec. The value of the button changes to stop. When I hit stop I call the clearinterval method. For some reason the clear interval method is not working.
这是我的投入
<input id="trigger" type="button" value="start"/>
我的 js 函数
$(function() {
$( #trigger ).click(function() {
var timerId = 0;
var trigger = $( #trigger ).val();
if(trigger == start ) {
timerId = setInterval(function() {
$( #trigger ).val( stop );
main();
}, 1000);
} else if(trigger == stop ) {
clearInterval(timerId);
$( #trigger ).val( start );
}
});
});