jQuery.extend

对jQuery对象的扩展,可以理解为静态方法,不需要实例jQuery就可以使用。

    <script type="text/javascript">
    <!--
        jQuery.extend({
            add: function(a, b) {
                return a + b;
            }
        });

        alert($.add(3, 4)); //7

    //-->
    </script>


jQuery.fn.extend

对jQuery元素的扩展,只能用在jQuery元素上,可以理解为普通方法。定义插件时需要返回this,以支持jQuery的链式操作。

    <script type="text/javascript">
    <!--
        jQuery.fn.extend({
            red: function() {
                return $(this).css('color', '#ff0000');
            }
        });

        $('#test').red();
    //-->
    </script>

相关文章:

  • 2021-08-21
  • 2021-09-16
  • 2021-05-20
  • 2022-01-09
  • 2021-07-23
  • 2021-05-31
  • 2021-08-16
猜你喜欢
  • 2021-04-14
  • 2021-11-25
  • 2022-03-09
  • 2021-09-20
  • 2022-01-22
  • 2022-12-23
相关资源
相似解决方案