DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> HTML基礎知識 >> HTML5詳解 >> 解決Firefox下不支持outerHTML問題代碼分享
解決Firefox下不支持outerHTML問題代碼分享
編輯:HTML5詳解     

代碼很簡單,如下:


復制代碼代碼如下:
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 + "</" + 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());
});
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved