方法一:$.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>

 

相关文章:

  • 2022-12-23
  • 2022-03-01
  • 2022-12-23
  • 2021-11-30
  • 2021-12-05
  • 2021-05-22
  • 2021-07-15
猜你喜欢
  • 2021-07-23
  • 2021-11-11
  • 2021-06-05
  • 2021-12-13
  • 2021-12-06
  • 2021-12-19
相关资源
相似解决方案