jQuery在ajaxForm之前验证

sup*_*led 3 validation jquery ajaxform

我正在尝试使用jQuery ajaxForm插件中的"beforeSubmit"选项来验证数据,但即使存在无效的表单字段,表单也会提交.我哪里出错了?谢谢,

$(document).ready(function() { 
function validator(){ 
        $("#commentForm").validate();
}

    $('#commentForm').ajaxForm({ 
        dataType: 'json',
        url: "http://highlandfamilyeyecare.com/contactengine.php",
        beforeSubmit:  validator,
        success:        function(data) { 
            $('ul.form').fadeOut("slow");
            $('ul.form').html(data.formula).slideDown('slow');}
    });
});
Run Code Online (Sandbox Code Playgroud)

和HTML:

<ul class="form">


    <li>    
        <form method="post" action="form.php" id="commentForm">

        <label class="white">Your Name</label>
        <input class="text-input required" type="text" name="name" /></li>

    <li>
        <label class="white">Email</label>
        <input class="text-input required email" type="text" name="email"/></li>

    <li>
        <li><input type='submit' value="Submit" />
        </form></li>

</ul>
Run Code Online (Sandbox Code Playgroud)

CWF*_*CWF 6

beforeSubmit()函数没有返回任何内容.

你想要:

function validator() { 
  return $("#commentForm").validate();
}
Run Code Online (Sandbox Code Playgroud)

假设$('#commentForm").validate()存在并正确返回true/false.