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的实例对象。

  • 相关阅读:
    ftp命令行敲不了
    转载 vsftpd安装
    ftp上传不了故障
    mysql导入数据方法和报错解决
    time使用方法
    python 进程Queue
    python 进程事件
    python 进程信号量
    python 进程锁
    python 守护进程
  • 原文地址:https://www.cnblogs.com/Ferrari/p/7089627.html
Copyright © 2011-2022 走看看