Javascript: 延迟提交工作不正常
Javascript: Delayed submit is not working correctly
https://jsfiddle.net/z1ctm0hd/
JSFiddle 生成了一个奇怪的错误列表(图片http://i.share.pho.to/7e8051a3_l.png),但是,自动提交在我的页面上运行,但没有请求的延迟。感谢任何人的帮助。
<form id='formBlokUziv' action='' method='post'>
<div class='onoffswitch'>
<input type='checkbox' name='onoffswitch1' value='1' onchange='setTimeout(document.getElementById("formBlokUziv").submit(), 5000);' class='onoffswitch-checkbox' id='myonoffswitch1' >
<label class='onoffswitch-label' for='myonoffswitch1'>
<span class='onoffswitch-inner'></span>
<span class='onoffswitch-switch'></span>
</label>
</div>
<div class='onoffswitch'>
<input type='checkbox' name='onoffswitch2' value='2' onchange='setTimeout(document.getElementById("formBlokUziv").submit(), 5000);' class='onoffswitch-checkbox' id='myonoffswitch2' >
<label class='onoffswitch-label' for='myonoffswitch2'>
<span class='onoffswitch-inner'></span>
<span class='onoffswitch-switch'></span>
</label>
</div>
<div class='onoffswitch'>
<input type='checkbox' name='onoffswitch3' value='3' onchange='setTimeout(document.getElementById("formBlokUziv").submit(), 5000);' class='onoffswitch-checkbox' id='myonoffswitch3' >
<label class='onoffswitch-label' for='myonoffswitch3'>
<span class='onoffswitch-inner'></span>
<span class='onoffswitch-switch'></span>
</label>
</div>
</form>
在 setTimeout
调用中作为第一个参数输入的命令将立即执行。将您的每个超时放入一个函数中,它会在指定的超时后 运行。像 -
setTimeout(function() { document.getElementById("formBlokUziv").submit() }, 5000);
https://jsfiddle.net/z1ctm0hd/
JSFiddle 生成了一个奇怪的错误列表(图片http://i.share.pho.to/7e8051a3_l.png),但是,自动提交在我的页面上运行,但没有请求的延迟。感谢任何人的帮助。
<form id='formBlokUziv' action='' method='post'>
<div class='onoffswitch'>
<input type='checkbox' name='onoffswitch1' value='1' onchange='setTimeout(document.getElementById("formBlokUziv").submit(), 5000);' class='onoffswitch-checkbox' id='myonoffswitch1' >
<label class='onoffswitch-label' for='myonoffswitch1'>
<span class='onoffswitch-inner'></span>
<span class='onoffswitch-switch'></span>
</label>
</div>
<div class='onoffswitch'>
<input type='checkbox' name='onoffswitch2' value='2' onchange='setTimeout(document.getElementById("formBlokUziv").submit(), 5000);' class='onoffswitch-checkbox' id='myonoffswitch2' >
<label class='onoffswitch-label' for='myonoffswitch2'>
<span class='onoffswitch-inner'></span>
<span class='onoffswitch-switch'></span>
</label>
</div>
<div class='onoffswitch'>
<input type='checkbox' name='onoffswitch3' value='3' onchange='setTimeout(document.getElementById("formBlokUziv").submit(), 5000);' class='onoffswitch-checkbox' id='myonoffswitch3' >
<label class='onoffswitch-label' for='myonoffswitch3'>
<span class='onoffswitch-inner'></span>
<span class='onoffswitch-switch'></span>
</label>
</div>
</form>
在 setTimeout
调用中作为第一个参数输入的命令将立即执行。将您的每个超时放入一个函数中,它会在指定的超时后 运行。像 -
setTimeout(function() { document.getElementById("formBlokUziv").submit() }, 5000);