<img src="http://c.csdn.net/bbs/t/5/i/pic_logo.gif" />
<script type="text/javascript">
var imgs = document.images;
var t = document.createElement("IMG");
t.src =  imgs[0].src; 
imgs[j].outerHTML = "_";
alert(t.src);//FF下支持outerHTML操作
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()); 
    }); 

</script>
我在网上找了一段代码加上后 似乎不管用???请问怎么操作!!!

解决方案 »

  1.   

    代码放在使用outerHTML之前<img id="img1" src="http://c.csdn.net/bbs/t/5/i/pic_logo.gif" />
    <script type="text/javascript">
    //FF下支持outerHTML操作
    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()); 
        }); 
    }
    document.getElementById("img1").outerHTML = "<img src=\"http://zi.csdn.net/210-60rz.gif\">"
    </script>
      

  2.   

    HTMLElement.prototype.__defineGetter__("outerHTML",function() { 
            if(this.parentElement)return this.parentElement.innerHTML;
            alert(this.parentElement)
            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!=undefined &&  !this.canHaveChildren)return str+" />"; 
            return str+">"+this.innerHTML+"</"+this.tagName+">"; 
        }); 
      

  3.   

    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!=undefined &&  !this.canHaveChildren)return str+" />";
            return str+">"+this.innerHTML+" </"+this.tagName+">";
        });