zoukankan      html  css  js  c++  java
  • jQuery的扩展

      我们自己通过扩展jQuery来达到 “通过$.xx(paras)的形式来进行调用某个jQuery对象的xx(paras)方法”。

    下面就是一个实例:

     1 (function(j){//这里的j是一个形参,表示传入的jQuery对象,j可以任意填写
     2     j.extend({//相当于给jQuery对象加上了一个属性readName,而这个属性是一个方法
     3         // 通过传入的jQuery对象,
     4         // 然后再用jQuery.exetend(functionName:function(){});
     5         // 这种方式扩展jQuery的方法,
     6 
     7         // 使用方法或者说是调用方式:$.readName('I am 你大爷 '); 
     8     readName:function(name){
     9         // alert(typeof this);
    10         // alert(typeof window);
    11         // alert(typeof this.name);
    12         console.log(typeof this.name);
    13         console.log(typeof this);
    14         if(name==null||name==undefined||name==''){
    15             // alert('没有入参name!');
    16             console.log('没有入参name!')
    17 
    18         }else{
    19             // alert('入参name:'+name);
    20             console.log('入参name:'+name);
    21     }
    22 }
    23 })
    24 })(jQuery)//这个jQuer一定要这样写,表示传入jQuery对象
  • 相关阅读:
    Document
    Document
    Document
    Document
    Document
    Document
    Document
    Document
    export和import 输出/接收模块变量的接口
    webpack:(模块打包机)
  • 原文地址:https://www.cnblogs.com/Sunnor/p/5172039.html
Copyright © 2011-2022 走看看