function DomElement(id){
this.dom = document.getElementById(id);
}
DomElement.prototype.html = function (val){
var ele = this.dom
if (val) {
ele.innerHTML = val
return this
}else{
return ele.innerHTML
}
}
DomElement.prototype.on = function (type,fn){
vae ele = this.dom
ele.addEventListener(type,fn)
return this
}
var div1 = new DomElement('div1')
console.log(div1.html());
div1.html('<p>这是一段文字</p>').on('click',function(){
console.log('clicked')
})
相关文章
- 02-06一个贴近实际开发原型链继承的l例子