zoukankan      html  css  js  c++  java
  • $.extend和$.fn.extend()

    1、$.extend(src)

       该方法就是将src合并到jquery的全局对象中去。

    2、$.fn.extend(src)
       该方法将src合并到jquery的实例对象中去。

    直接来看代码吧:

    $(function () {

    $.extend({
    hello: function () { console.log('hello'); }
    });

    $.fn.extend({
    hi: function () { console.log('hi'); }
    });

    $.hello();
    $.hi();
    });

    执行$.hello()成功,执行$.hi()报错,因为hello()是jquery的全局对象中,所以执行$.hello()可以访问,而$.hi()不存在,故报错。

    执行如下代码:

    $(function () {

    $.extend({
    hello: function () { console.log('hello'); }
    });

    $.fn.extend({
    hi: function () { console.log('hi'); }
    });

    $("div:first").hi();
    $("div:first").hello();
    });

     

    $("div:first").hi()执行成功,$("div:first").hello()报错,因为$("div:first")是一个jquery的实例对象。

  • 相关阅读:
    读操作
    读锁与写锁
    Mvcc
    readView
    版本链
    事务的隔离性
    索引的代价
    keras backend的修改
    caffe 笔记
    菜品识别 SDK调用
  • 原文地址:https://www.cnblogs.com/Ferrari/p/7089627.html
Copyright © 2011-2022 走看看