-1

Have two different events happening on the click. Using jQuery and trying to bind the to the submit button to different calls. One is a call to jquery.validate, the other is a call to a get response. Both of the events are working fine, but I want them tied together. Right now, the first click does a call to the server and receiving some JSON back (there's more code),

$("#validateButton").bind('click', function () {
  var someVariable = $("#someVariable").val();
}

 //Bind button to click
 $('#validateButton').bind('click', function () {
 //Implement Validate on this form ID
 $('#someForm').valid();
});
  //Ensure we're ready
$().ready(function () {


$("#someVariable").validate({

    rules: {
        someVariable: {
            required: true,
        },
    },

    messages: {
        accntTypeCL: {
            required: "Blah",

        },
    }
});

});
4

1 回答 1

1

您不需要绑定.valid()到单击提交按钮,因为单击提交时已经自动检查了表单的状态。

你只需要.validate()在 DOM 上初始化表单就可以了。然后使用它的内置功能来完成单击按钮 submitHandler:后需要执行的所有操作/其他操作。submit

$(document).ready(function() {

    $('#theForm').validate() {
        // your validation rules and plugin options,

        submitHandler: function(form) {
            // whatever code you want to run upon clicking submit
            var someVariable = $("#someVariable").val();
            form.submit();
        }
    });

});

简单演示:

http://jsfiddle.net/tyGNC/

于 2013-01-06T00:02:12.313 回答