Jquery validation plugin - TypeError: $(…).validate is not a function

后端 未结 8 1075
不知归路
不知归路 2020-12-01 08:45

My script throw errors:

TypeError: jQuery.validator is undefined additional-methods.js:20 TypeError: $(...).validate is not a function index.php:115

相关标签:
8条回答
  • 2020-12-01 09:22

    You didn't include the base jQuery Validation library:

    <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script>
    

    Put that before the additional methods library. (BTW this is a hosted version, download your own if you want)

    0 讨论(0)
  • 2020-12-01 09:28

    You're not loading the validation plugin. You need:

    <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
    

    Put this before the line that loads the additional methods.

    Also, you should get the additional methods from the CDN as well, rather than jquery.bassistance.de.

    Other errors:

    [4.20]
    

    should be

    [4,20]
    

    and

    rangelenght:
    

    should be:

    rangelength:
    
    0 讨论(0)
  • 2020-12-01 09:28

    Include jquery.validate.js before additional-methods.js.

    $.validate() method is defined there

    0 讨论(0)
  • 2020-12-01 09:29

    I had the same problem. I am using jquery-validation as an npm module and the fix for me was to require the module at the start of my js file:

    require('jquery-validation');
    
    0 讨论(0)
  • 2020-12-01 09:30

    If using VueJS, import all the js dependencies for jQuery extensions first, then import $ second...

    import "../assets/js/jquery-2.2.3.min.js"
    import "../assets/js/jquery-ui-1.12.1.min.js"
    import "../assets/js/jquery.validate.min.js"
    import $ from "jquery";
    

    You then need to use jquery from a javascript function called from a custom wrapper defined globally in the VueJS prototype method.

    This safeguards use of jQuery and jQuery UI from fighting with VueJS.

    Vue.prototype.$fValidateTag = function( sTag, rRules ) 
    {
        return ValidateTag( sTag, rRules );
    };
    
    function ValidateTag( sTag, rRules )
    {
        Var rTagT = $( sTag );
        return rParentTag.validate( sTag, rRules );
    }
    
    0 讨论(0)
  • 2020-12-01 09:37

    For me problem solved by changing http://ajax... into https://ajax... (add an S to http)

    https://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js
    
    0 讨论(0)
提交回复
热议问题