为什么我得到[object HTMLParagraphElement] [英] Why did I get [object HTMLParagraphElement]
本文介绍了为什么我得到[object HTMLParagraphElement]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新手。这是我的代码:
I am a newbie. Here is my code:
<html>
<head>
<script type="text/javascript">
function replyOne () {
document.getElementById("comment_content").value = document.getElementById("username")
}
</script>
</head>
<body>
<p id="username">Jack</p>
<textarea id="comment_content" ></textarea>
<button onclick="replyOne()">Copy Text</button>
</body>
</html>
我希望当我点击按钮时,它会将'Jack'复制到textarea。
但它只是写'[object HTMLParagraphElement]'。
I expect that when I click the button, it will copy 'Jack' to the textarea. But instead it just writes '[object HTMLParagraphElement]'.
推荐答案
它应该是:
document.getElementById("comment_content").value =
document.getElementById("username").innerHTML
如果没有 .innerHTML
,它会尝试复制实际元素,而不是它的内容。
Without the .innerHTML
, it will try to copy in the actual element, not its content.
这篇关于为什么我得到[object HTMLParagraphElement]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文