2011-06-21 70 views
0

我想在提交表單前顯示一個提示框。使用jQuery確認表單提交

如果用戶按是,那麼表單將提交,否則不會。 有沒有使用jQuery的解決方案?

+0

「我需要幫助夥伴!!!」在這裏不受歡迎。 – ThiefMaster

回答

10

您可以通過攔截html表單的提交事件來使用javascript confirm(message) : boolean函數。

$("#html_form").submit(function(e){ 
    if (!confirm("should i really submit")) 
    { 
     e.preventDefault(); 
     return; 
    } 
}); 
3
$('#yourform').submit(function(e) { 
    if(!confirm('really submit the form?')) { 
     e.preventDefault(); 
     return; 
    } 
    // submit the form via ajax, e.g. via the forms plugin 
    // http://jquery.malsup.com/form/ 
});