问题是这样的: 当您打开复选框时,打开计时器,关闭复选框并关闭计时器。我试过了,但没有尝试。复选框和SetInterval
$('#apply').click(function() {
if ($('#autoupdate').prop("checked")) {
var timerId = setInterval(function() {
$.ajax({
type: "post",
url: "1.php",
cache: false,
success: function (html) {
$("#result").html(html);
}
});
}, 1000);
} else {clearInterval(timerId);}
});
Autoupdate: <input type="checkbox" id="autoupdate">
<input id="apply" type="submit" value="Apply">
<div id="result"></div>
感谢您的答案,但它不能解决问题,定时器仍然继续。 – user1816319