2011-01-12 225 views
1

我有喜歡的JavaScript關閉對話框時,如何防止jQuery驗證從驗證

http://jsfiddle.net/8JXTk/1/

只是snipplet ...

$dialog.dialog({ 
    title: "Add Link", 
    buttons: { 
    "Add Link": function() { 
     var $this = $(this); 
     if ($this.valid()) { 
     alert($this.find("input[name=txtURL]").val()); 
     } else { 
     $this.find("input.error:first").effect("highlight").focus(); 
     } 
    }, 
    "Cancel": function() { 
     $(this).dialog("close"); 
    } 
    }, 
    open: function() { 
    $this = $(this); 
    $this.find("input[name=txtURL]").val("http://").focus(); 
    } 
}); 

,你可以看到取消按鈕的處理程序只是爲了關閉對話。爲什麼當我取消對話框時驗證正在運行? (當你取消,你可以看到出現在錯誤的閃光燈)

回答

2

更換

$dialog.validate({ 

$('.markdownEditorDialogs').validate({ 

您要驗證對話框,但您必須驗證剛剛創建的窗體。