<script>
// 面向过程
var div=document.createElement('div');
document.body.appendChild(div);
div.style.width="200px"
div.style.height="200px"
div.style.border="1px solid #000"
//面向对象
function DivTag(){
this.DOM=document.createElement('div');
this._add=function(node){
node.appendChild(this.DOM);
return this;
}
this._changeStyle=function(option){
for(var i in option)
{
this.DOM.style[i]=option[i];
}
return this;
}
}
//调用
new DivTag()._setStyle({'width':'800px','height':'200px','border':'1px solid #000'})._add(document.body);
</script>
js 面向对象Demo
最新推荐文章于 2022-11-10 12:22:00 发布