2016-03-02 67 views
0

https://jsfiddle.net/z1ctm0hd/的Javascript:延遲提交不正確

的jsfiddle產生錯誤的奇怪的名單(PIC 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> 

回答

2

輸入的命令如在setTimeout調用的第一個參數將被立即執行。將每個超時放入一個函數中,並在指定的超時後運行。類似 -

setTimeout(function() { document.getElementById("formBlokUziv").submit() }, 5000); 
+0

Thx非常多,問題解決了。 –