zoukankan      html  css  js  c++  java
  • jQuery扩展extend一

      把这个扩展写在这里,以后要是忘了可以回头查看。

     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         this_ : this,
     9         timeId: null,
    10         flagWyl:null,
    11         readName : function(name) {
    12             // alert(typeof this);
    13             // alert(typeof window);
    14             // alert(typeof this.name);
    15             console.log(typeof this.name);
    16             console.log(typeof this);
    17             if (name == null || name == undefined || name == '') {
    18                 // alert('没有入参name!');
    19                 console.log('没有入参name!')
    20 
    21             } else {
    22                 // alert('入参name:'+name);
    23                 console.log('入参name:' + name);
    24             }
    25         },
    26         //封装提示的内容:
    27         Walert:function(msg){
    28             alert('系统异常:'+msg);
    29         },
    30         /**
    31          * toId:需要设置时间的表单的Id,
    32          * flag:true的时候,设置本地时间格式,false,设置成通用格式
    33          */
    34         WsetTime:function(toId,flag){
    35             var d = new Date();
    36 //            window.setInterval('$.WsetTime('+toId+','+flag+')',10000);
    37             if(flag){
    38                 $('#'+toId+'').attr('value',d.toLocaleString());
    39             }else{
    40                 $('#'+toId+'').attr('value',d.toTimeString());
    41             }
    42 //            $.this_ = this;//把当前对象传给 存储临时变量的对象,当前对象即WsetTime()这个函数
    43             $.timeId = toId;
    44             $.flagWyl = flag;
    45         },
    46         /**
    47          * 设置时间间隔
    48          */
    49         WsetGap:function(intervalTime){
    50             if($.timeId){
    51                 window.setInterval('$.WsetTime('+$.timeId+','+$.flagWyl+')',intervalTime);
    52             }
    53         },
    54         /**
    55          * 封装console.log()方法
    56          */
    57         logW:function(paras){
    58             console.log('logW:'+paras);
    59         }
    60         
    61     })
    62 })(jQuery)// 这个jQuer一定要这样写,表示传入jQuery对象

    以上的代码的前提是要在项目中引入jQuery.js,以上的js链接:myJqueryExtend.js

  • 相关阅读:
    全面兼容的Iframe 与父页面交互操作
    Windows Phone 8.1 新特性
    android手电筒源码
    最新android版QQ布局效果 v4.7.0全新UI源码
    点击弹出动态菜单效果ios源码
    本app(仿手机支付宝界面)ios源码
    WP应用开发笔记
    关于移动,爱游,联通三家运营商付费SDK的融合方案
    cocos2d-x学习总结01引言
    新站seo如何进行站内优化
  • 原文地址:https://www.cnblogs.com/Sunnor/p/5174265.html
Copyright © 2011-2022 走看看