<!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>
不是很好用,可以读取,也可以赋值,但不可以追加
有机会好好研究