如何在提交函数中使用我的jQuery验证器?

时间:2014-07-13 22:46:54

标签: javascript jquery jquery-validate

一旦开始"开始"单击按钮,我希望表单首先验证,然后显示错误消息,如果它没有验证或者在submit()函数下转到网站。

将此内容放入javascript中的正确方法是什么?我是否需要开始function() {....}或者我只是按照我的方式进行操作,是否有办法在是否验证时返回真或假?这是我第一次在javascript中编码

HTML:

<form action="" method="post" class="form-horizontal" id="new-pbc-form">
    <div class="control-group">
        <label class="control-label" for="project-name">Project Name</label>
        <div class="controls">
            <input type="text" name="name" id="projectname" placeholder="Project Name" />
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="project-version">Project Version</label>
        <div class="controls">
            <input type="text" name="version" id="project-version" placeholder="Project Version" />
        </div>
    </div>
    <div class="control-group">
        <div class="controls">
            <button type="submit" class="btn" id="pbc-start-btn">Start</button>
        </div>
    </div>
</form>

jQuery的:

    $('#new-pbc-form').validate({ // initialize the plugin
        rules: {
            name: {
                required: true
            },
            version: {
                required: true
            }
        }
    });
    $('#new-pbc-form').submit(function () {
        window.location.href = "WebForm2.aspx";
        return false;
    });

0 个答案:

没有答案
相关问题