jquery 链式操作

时间:2019-05-15 23:50:30   收藏:0   阅读:204
 (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");

原文:https://www.cnblogs.com/longtao/p/10872771.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!