jQuery and other libraries, and the usage of '$'

前端 未结 6 765
孤独总比滥情好
孤独总比滥情好 2021-01-07 03:37

I have a quick, beginners-type-question. If I were to use jQuery and some other framework, would the following statement be problematic:

jQuery(document).rea         


        
6条回答
  •  不要未来只要你来
    2021-01-07 03:43

    When using multiple libraries that make use of $, the common practice is to use noConflict mode and reassign the $ for jQuery to something else.

    var $jq = jQuery.noConflict();
    
    $jq( function() {
        $jq("input[name='password']").focus( function() {
            $jq("input[value='login']").attr("checked","checked");
        });
    });
    

    In plugin development, a common way to handle this is to pass `$' in as a parameter to a function defining your plugin definition and applying the function to the jQuery object.

    ;(function($) {
        ...
    })(jQuery);
    

提交回复
热议问题