正在加载...
广而告知:

FF也可以用上outerHTML

Javascript>> 2009年06月30日
【字体大小 :

版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://monw3c.blogbus.com/logs/41695366.html

FF下是不能认识outerHTML,因为outerHTML不是W3C的标准属性,网上使用DOM原型扩展方法解决,代码如下:

if(typeof(HTMLElement)!="undefined" && !window.opera) 

    HTMLElement.prototype.__defineGetter__(
"outerHTML",function() 
    

        
var a=this.attributes, str="<"+this.tagName, i=0;for(;i<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+">"
    }
); 
    HTMLElement.prototype.__defineSetter__(
"outerHTML",function(s) 
    

        
var r = this.ownerDocument.createRange(); 
        r.setStartBefore(
this); 
        
var df = r.createContextualFragment(s); 
        
this.parentNode.replaceChild(df, this); 
        
return s; 
    }
); 
    HTMLElement.prototype.__defineGetter__(
"canHaveChildren",function() 
    

        
return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase()); 
    }
); 
}
 


历史上的今天:

随写~ 2008年06月30日

随机文章:

一张好图 2009年07月28日
JS脚本跨域解决方案 2008年11月14日
JavaScript生成xml 2008年10月07日

收藏到:Del.icio.us




广而告知:


^ 回顶部
推荐网站: