代码很简单,如下:
代码如下:
var pro = window.htmlelement.prototype;
pro.__definegetter__(outerhtml, function(){
var str = < + this.tagname;
var a = this.attributes;
for(var i = 0, len = a.length; i < len; i++){
if(a.specified){
str += + a.name + '=' + a.value + '';
}
}
if(!this.canhavechildren){
return str + />;
}
return str + > + this.innerhtml + </ + this.tagname + >;
});
pro.__definesetter__(outerhtml, function(s){
var r = this.ownerdocument.createrange();
r.setstartbefore(this);
var df = r.createcontextualfragment(s);
this.parentnode.replacechild(df, this);
return s;
});
pro.__definegetter__(canhavechildren, function(){
return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagname.tolowercase());
});
更多网页制作信息请查看: 网页制作 |