牧羊岛

懒是不会有好果子吃滴//

导航

火狐模拟outerHTML

Posted on 2010-05-05 10:19  牧羊岛  阅读(915)  评论(0编辑  收藏  举报

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>

<body><input name="" type="text" id="ss1" />
</body>
</html>
<script>
/*outerHTML for Firefox*/
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 d = document.createElement("DIV"); d.innerHTML = s;
for(var i=0; i<d.childNodes.length; i++)
this.parentNode.insertBefore(d.childNodes[i], this);
this.parentNode.removeChild(this);
});
HTMLElement.prototype.__defineGetter__(
"canHaveChildren",function()
{
return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
});
}
/*end outerHTML*/
alert(document.getElementById('ss1').outerHTML);
txt
= document.getElementById('ss1').outerHTML;
document.getElementById(
'ss1').outerHTML = txt + '13';
alert(document.getElementById(
'ss1').outerHTML);
</script>

不是很好用,可以读取,也可以赋值,但不可以追加

 

有机会好好研究

 

 

/*outerHTML for Firefox*/