纯js学写插件

//无限链式编程

function $(id){
return new fn(id);
}

var fn = function(id) {
return this.getElementById(id);

};

fn.prototype.getElementById=function(id){
this.element = document.getElementById(id);
return this;
}

fn.prototype.Method=function(){
this.element.style.color="red";
return this;
}

fn.prototype.FontSizes=function(){
this.element.style.fontSize="30px";
return this;
}

window.onload=function(){
$("newtxt").Method().FontSizes();
}

 

posted @ 2015-10-26 00:36  luoyiming  阅读(79)  评论(0)    收藏  举报