我在 JSP 中使用 java 脚本,问题是我需要在选择复选框上自动刷新它工作正常但在取消选择时它不会停止自动刷新事件。plz 建议 提前致谢
function autorefresh() {
var isChecked = document.getElementById("is_check").checked;
var time = 0;
if (isChecked == true) {
time = setInterval(function () {
showExport()
}, 5000);
} else if (isChecked == false) {
clearInterval(time);
}
}
最佳答案
将时间变量定义为全局变量:
window.time=0; //global declaration
function autorefresh() {
var isChecked = document.getElementById("is_check").checked;
if (isChecked == true) {
time = setInterval(function () {
showExport()
}, 5000);
} else if (isChecked == false) {
clearInterval(time);
}
}
关于Javascript 复选框选择/取消选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21398195/