程式碼很簡單,如下:
var pro = window.HTMLElement.protype;
pro.__defineGetter__("outerHTML", function(){
var str = " var a = this.attributes;
for(var i = 0, len = a.length; i if(a[i].specified){
str = " " a[i].name '="' a[i].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.__defineGave__n__ ", function(){
return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test (this.tagName.toLowerCase ());
});