Jquery中$与$.fn的区别

1.$本质上其实是Jquery的另一种表现形式

2.Jquery方法拓展(类似于java类中添加静态方法)

        (function ($) {
            $.test2 = function (a, b)
            {
                alert(a+b);
            }
        })(jQuery);
        $.test2(1,5);
方法1
        (function ($) {
            $.extend({
                test: function (a, b) {
                    alert(a-b)
                }
            });
        })(jQuery);
        $.test(2,1);
方法2

3.$.fn是指jquery的命名空间,加上fn上的方法及属性,会对jquery实例每一个有效

        (function ($) {
            $.fn.add = function (a, b) {
                alert(a + b);
            }
        })(jQuery);
        $("#source").add(1,4);
View Code
        (function ($) {
            $.fn.extend({
                add:function(a,b)
                {
                    alert(a + b);
                }
            });
        })(jQuery);
        $("#source").add(1, 4);
方法2

jQuery.fn = jQuery.prototype

源码:jQuery.fn = jQuery.prototype = { 
   init: function( selector, context ) {//....  
   //...... 
}; 

原文地址:https://www.cnblogs.com/liandy0906/p/7351772.html