类似于jquery中的链式结构封装

来源:互联网 发布:淘宝介入卖家没有发票 编辑:程序博客网 时间:2024/06/06 05:20

封装方法使用prototype

function changestyle(select){    this.style=document.querySelectorAll(select).style;}changestyle.prototype.color=function(color){    this.style.color=color;}changestyle.prototype.height=function(height){    this.style.height=height;}changestyle.prototype.width=function(width){    this.style.width=width;}

调用方法:

var tmp=new changestyle("#id")tmp.color('red').height('20px').width('20px');


1 0
原创粉丝点击