jquery 链式操作

 (function(window){
            function jQuery(element){
                    return new jQuery.prototype.init(element);
            }
            jQuery.prototype = {
                constructor : jQuery,
                init : function(element){
                  var el = document.querySelectorAll(element);
                  for(var i=0,len=el.length;i<len;i++){
                      this[i] = el[i];
                  }
                  this.length = el.length;
                },
                html : function(h){
                    this[0].innerHTML = h;
                    return this;
                },
                css : function (k,v) {
                    this[0].style[k] = v;
                    return this;
                }
            }
            jQuery.prototype.init.prototype = jQuery.prototype;
            window.$ = window.jQuery = jQuery
        })(window)
        $("div").html("sssssssss").css("color","yellow");

猜你喜欢

转载自www.cnblogs.com/longtao/p/10872771.html