jquery - difference between $.functionName and $.fn.FunctionName

后端 未结 3 743
旧时难觅i
旧时难觅i 2020-11-30 18:46

In jQuery, I have seen both the following ways of defining a jQuery function:

$.fn.CustomAlert = function() {
  alert(\'boo!\');
};

$.CustomAlert = function         


        
3条回答
  •  一生所求
    2020-11-30 19:21

    A

    $.a = function() {
      return "hello world";
    };
    
    alert($.a());
    

    B

    $.fn.b = function() {
      return "hello " + $(this).length + " elements";
    }
    
    alert($("p").b());
    

提交回复
热议问题