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>
答案 0 :(得分:2)
作为setTimeout
调用中的第一个参数输入的命令将立即执行。将每个超时放入一个函数中,它将在指定的超时后运行。像 -
setTimeout(function() { document.getElementById("formBlokUziv").submit() }, 5000);