如何防止jQuery验证关闭对话框时的验证

时间:2011-01-12 10:16:45

标签: jquery jquery-validate

我有像

这样的javascript

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

只是一个小贴士...

$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();
  }
});

你可以看到取消按钮的处理程序就是关闭对话框。为什么取消对话框时运行验证? (取消时,您可以看到出现错误的闪烁)

1 个答案:

答案 0 :(得分:2)

替换

$dialog.validate({

$('.markdownEditorDialogs').validate({

您正在验证对话框,但您必须只验证您创建的表单。

相关问题