Javascript JS:需要关于setTimeout()行为的解释吗
我有两个按钮。第一个运行提醒,另一个停止提醒:Javascript JS:需要关于setTimeout()行为的解释吗,javascript,range,settimeout,Javascript,Range,Settimeout,我有两个按钮。第一个运行提醒,另一个停止提醒: <input type="range" id="range" min="1" max="480" onInput="syncValues('intrvl',this);" /> <input type="text" id="intrvl" value="0.07" onInput="syncValues('range',this);" /> 我想,在点击停止按钮后,超时将被删除,脚本将立即终止。但它让我明白了。我检查了调用
<input type="range" id="range" min="1" max="480" onInput="syncValues('intrvl',this);" />
<input type="text" id="intrvl" value="0.07" onInput="syncValues('range',this);" />
我想,在点击停止按钮后,超时将被删除,脚本将立即终止。但它让我明白了。我检查了调用makedecisiontrue后发生的情况,发现函数没有得到cancel参数,首先,如上所述,它调用confirm,只有在它出现后,参数才会出现。
有人能解释一下如何修复它以及为什么会发生吗 在stop处理程序的开头有一个对makedecision函数的无参数调用:stop onclick first中的代码调用'makedecision;`没有参数;这看起来和应该触发确认的东西一模一样。。。你是对的,我感到羞耻:把你的评论作为回答,我会用它。
function syncValues(inpToId, inpFrom) {
if (!inpFrom) inpFrom = document.getElementById('intrvl');
document.getElementById(inpToId).value = inpFrom.value;
}
window.onload = function() {
syncValues('range');
var makeDecition = (function() {
var tm,
stp = false,
gotm = false,
sttm = function(cancel) {
var min = document.getElementById('intrvl').value;
tm = setTimeout(makeDecition, min * 60 * 1000);
};
return function(cancel) {
console.dir(cancel);
if (cancel) {
stp = false;
clearTimeout(tm);
} else {
if (gotm) {
if (!stp)
if (!confirm("Go on?")) gotm = null;
} else {
stp = false;
gotm = true;
}
if (gotm !== null) sttm();
}
};
}());
document.getElementById('start').onclick = function(event) {
makeDecition();
event.currentTarget.disabled = true;
};
document.getElementById('stop').onclick = function(event) {
makeDecition();
document.getElementById('start').disabled = false;
makeDecition(true);
};
};