Home >Web Front-end >H5 Tutorial >Code sharing to solve the problem of not supporting outerHTML under Firefox_html5 tutorial skills

Code sharing to solve the problem of not supporting outerHTML under Firefox_html5 tutorial skills

WBOY
WBOYOriginal
2016-05-16 15:47:431563browse

代码很简单,如下:


复制代码
代码如下:

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[i].specified){
str = " " a[i].name '="' a[i].value '"';
}
}
if(!this.canHaveChildren){
return str " />";
}
return str ">" this.innerHTML "";
});
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());
});
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn