onkeyup and onfocusout is not working in jQuery Validate

前端 未结 1 535
说谎
说谎 2020-11-30 14:54

I am using jQuery Validate plugin for the validation purpose. I have to real time validation on the form. For example if a first name is required, then user

相关标签:
1条回答
  • 2020-11-30 15:26

    You would never use the .valid() method within the .validate() method. Refer to the source code of onkeyup and onfocusout to see how it's done.

    Use this.element(element) instead of $(element).valid()

    To over-ride the default functionality ("lazy validation") of onkeyup and onfocusout and use "eager" validation instead...

    $('#myform').validate({
        onkeyup: function(element) {
            this.element(element);  // <- "eager validation"
        },
        onfocusout: function(element) {
            this.element(element);  // <- "eager validation"
        }
        ....
    

    DEMO: http://jsfiddle.net/ajy5j8jq/

    0 讨论(0)
提交回复
热议问题