2010-10-15 92 views

回答

0

您可以嘗試綁定提交事件偵聽器。
HTML示例:

<form id="form" action="javascript:alert('form submitted !!!')"> 
    <input id="btn" type="submit"> 
</form> 

例的javascript:

$('form').submit(function(e) { 
    if (!confirm('Are you sure you want to submit?')) { 
     return false; 
    } 
}); 

//1: simulate a click event triggered directly 
window.setTimeout('alert("simulating click ...");document.getElementById("btn").click();', 3000); 

//2: simulate a submit event triggered directly 
window.setTimeout('alert("simulating submit ...");document.getElementById("form").submit();', 6000); 

//3: simulate a click event triggered by jQuery 
window.setTimeout('alert("simulating $.click ...");$("#btn").click();', 9000); 

//4: simulate a submit event triggered by jQuery 
window.setTimeout('alert("simulating $.submit ...");$("#form").submit();', 12000);​ 

​ 

您可以測試這個jsFiddle live example

點擊該按鈕(或直接在DOM節點上調用.click())或使用$.submit觸發攔截器事件,而是直接對DOM形式節點失敗使用$.click.submit()呼叫。
所以1和4的工作,2和3不
(需要更多的調查)