方法一:$.extend({ funname:function(){} }) ,该方法与标签无关
例如,自定义求最大值和最小值的方法
<p>自定义方法</p><p id="max"></p><p id="min"></p><script> ???$.extend({max:function (a,b) { ?????????return a>b?a:b; ???????}}) ???$.extend({min:function (a,b) { ?????????return a<b?a:b; ???????}}) ???$(‘#max‘).html(‘4和8的最大值为‘+$.max(4,8)); ???$(‘#min‘).html(‘4和8的最小值为‘+$.min(4,8));</script>
方法二:$.fn.extend({ funname:function(){} }) ,定义与标签相关的方法
<p>自定义方法</p><p>hello world</p><p>happy new year</p><script> ???$.fn.extend({ ???????getHtml:function () { ???????????for(var i=0;i<this.length;i++){ ???????????????console.log($(this)[i].innerHTML)} ???????} ???}) ???$(‘p‘).getHtml()</script>
jQuery自定义方法
原文地址:https://www.cnblogs.com/Forever77/p/10355764.html