Javascript复选框选择/取消选择

时间:2014-01-28 06:12:01

标签: javascript

我在JSP中使用java脚本问题是我需要在selectin复选框上自动刷新它工作正常但是取消选择它不会停止自动刷新活动.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);
    }
}

2 个答案:

答案 0 :(得分:1)

那是因为你在time上下文中定义autorefresh变量,所以它不再存储间隔的ID,你应该在函数之外定义它。

答案 1 :(得分:1)

将时间变量定义为全局:

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);
    }
}
相关问题