如何传递输入字段的值以使其成为函数的间隔?
function myTasksInProgressNext() {
// the value of this is 1 for example;
var x = parseInt(document.getElementById('txt').value);
var y = x * 60000;
window.open('remindInProgress.php','blank', 'width=200, height=200');
}
var t3 = setInterval(function(){myTasksInProgressNext()}, y);
这是正确的吗?
答案 0 :(得分:0)
您应该在函数外定义x
和y
变量:
var x = parseInt(document.getElementById('txt').value);
var y = x * 60000;
function myTasksInProgressNext() {
window.open('remindInProgress.php','blank', 'width=200, height=200');
}
var t3 = setInterval(function () {
myTasksInProgressNext();
}, y);
答案 1 :(得分:0)
HTML:
<form id="interval-form">
<input type="text" name="timeout" value="1000"/>
</form>
<div id="start-btn" onclick="onStartClick()" >START</div>
JS:
function runThis() {
/* code */
}
var interval;
function onStartClick() {
var form = document.getElementById('interval-form');
var timeout = parseInt(form['timeout'].value, 10);
interval = setInterval(runThis, timeout)
}