问答详情
源自:9-15 替换元素节点replaceChild()

好好学习!

    <script type="text/javascript">      
        function replaceMessage(){        
            var newnode =document.createElement("i");        
            var oldnode =document.getElementById("oldnode");        
            var oldnodetext=oldnode.innerText;        
            var newnodetext =document.createTextNode(oldnodetext);        
            newnode.appendChild(newnodetext);        
            for(const e of oldnode.attributes){   	        	
                if(e.name=="id"){        		
                    newnode.setAttribute(e.name,"newnode");        		
                    continue;        	
                }        	
                newnode.setAttribute(e.name,e.value);        
            }		
            oldnode.parentNode.replaceChild(newnode,oldnode);          
        }      
    </script>


提问者:沐沐3381925 2020-12-02 20:18

个回答

  • 唐好胜666
    2021-06-30 17:51:19

    加油啊