定义和定义.amd是什么意思?

时间:2015-04-20 09:50:11

标签: javascript jquery jquery-plugins

我刚学习jquery插件,我找到了这段代码。我不太了解javascript,但我喜欢这种语言,我尝试学习越来越多的东西,请告诉我越来越多。

(function( factory ) {
if ( typeof define === "function" && define.amd ) {
    define( ["jquery"], factory );
} else {
    factory( jQuery );
       }
}(function( $ ) {

$.extend($.fn, {
// http://jqueryvalidation.org/validate/
validate: function( options ) {

    // if nothing is selected, return nothing; can't chain anyway
    if ( !this.length ) {
        if ( options && options.debug && window.console ) {
            console.warn( "Nothing selected, can't validate, returning nothing." );
        }
        return;
    }



    // check if a validator for this form was already created
    var validator = $.data( this[ 0 ], "validator" );
    if ( validator ) {
        return validator;
    }


    // Add novalidate tag if HTML5.
    this.attr( "novalidate", "novalidate" );

    validator = new $.validator( options, this[ 0 ] );
    $.data( this[ 0 ], "validator", validator );

    if ( validator.settings.onsubmit ) {

        this.validateDelegate( ":submit", "click", function( event ) {
            if ( validator.settings.submitHandler ) {
                validator.submitButton = event.target;  
            }
            // allow suppressing validation by adding a cancel class to the submit button
            if ( $( event.target ).hasClass( "cancel" ) ) {
                validator.cancelSubmit = true;
            }

0 个答案:

没有答案