Why did I get [object HTMLParagraphElement]

后端 未结 2 1903
醉酒成梦
醉酒成梦 2021-01-02 16:03

I am a newbie. Here is my code:


  
    

        
相关标签:
2条回答
  • 2021-01-02 16:50

    It should be:

    document.getElementById("comment_content").value =
        document.getElementById("username").innerHTML
    

    Without the .innerHTML, it will try to copy in the actual element, not its content.

    0 讨论(0)
  • 2021-01-02 16:51

    You can use textContent,innertext,innerHTML.But two of them are browser specific and innerHTML can work on three major browser.

    Also you can parse the dom by parent children combination and will get required value.

     function replyOne () {
        document.getElementById("comment_content").value=document.getElementById("username").innerHTML;
    
        //OR 
        document.getElementById("comment_content").value=document.getElementById("username").textContent;
    
        }
    
    0 讨论(0)
提交回复
热议问题