zoukankan      html  css  js  c++  java
  • miniJquery

    (function () {

    var _$ = window.$;
    var _jQuery = window.jQuery;
    //暴露外部使用的一个接口
    var jQuery = window.jQuery = window.$ = function(selector){

    return new jQuery.fn.init(selector);
    };

    //处理原型对象
    jQuery.fn = jQuery.prototype = {
    init:function(selector){
    var elements = document.getElementsByTagName(selector);
    Array.prototype.push.apply(this,elements);
    return this;
    },
    jQuery:"1.0.0",
    length:0,
    size:function(){
    return this.length;
    }

    };
    jQuery.fn.init.prototype = jQuery.fn;
    //实现继承,并且只处理只有一个参数,也就是插件的扩展
    jQuery.extend = jQuery.fn.extend = function(){
    var o = arguments[0];
    for(var p in o){
    this[p] = o[p];
    }
    };

    //添加静态方法
    jQuery.extend({
    trim:function(text){
    return (text||"").replace(/^\s+|\s+$/g,"");
    },
    noConflict:function(){
    window.$ = _$;
    window.jQuery = _jQuery;
    return jQuery;
    }
    });
    //添加实例方法

    jQuery.fn.extend({
    get:function(num){
    return this[num];
    },
    each:function(fn){
    for(var i = 0 ;i< this.length; i++){
    fn(i,this[i]);
    }
    return this;
    },
    css:function(){
    var l = arguments.length;
    if(l == 1){
    return this[0].style[arguments[0]];
    } else {
    var name = arguments[0];
    var value = arguments[1];
    this.each(function(index,ele) {
    ele.style[name] = value;

    });
    }
    return this;
    },
    });

    })();

  • 相关阅读:
    5. 详解创建Vue实例传入的options【暂时3个】
    编程的小知识点:
    4. Vue的 MVVM模式
    3. Vue做一个计数器 --新属性:methods、新的指令:@click
    8. Spring 注解开发(原始注解)
    2. 第一个Vue程序
    1.VUE 的安装
    【洛谷 3388】割点
    【洛谷 1063】能量项链
    三堆石子
  • 原文地址:https://www.cnblogs.com/chenze/p/7899949.html
Copyright © 2011-2022 走看看