1. 程式人生 > >jquery 鏈式操作

jquery 鏈式操作

new for truct window prototype ret const func cti

 (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");

jquery 鏈式操作