Html 如何让onclick按钮在输入框中显示文本

Html 如何让onclick按钮在输入框中显示文本,html,button,input,onclick,Html,Button,Input,Onclick,我在处理更复杂的代码块时遇到了这个问题,所以我开始在电影《七人行》中使用html“笑话”,并意识到这是同一个问题。为什么当我点击按钮时它什么都不做?我尝试过添加一个函数和脚本,也遇到了同样的问题。我希望它在您单击按钮时显示(以前为空白)输入框内的文本 <html> <body> The Box:<input type="text" id="thebox" value="" size=10> <br><input type="button" v

我在处理更复杂的代码块时遇到了这个问题,所以我开始在电影《七人行》中使用html“笑话”,并意识到这是同一个问题。为什么当我点击按钮时它什么都不做?我尝试过添加一个函数和脚本,也遇到了同样的问题。我希望它在您单击按钮时显示(以前为空白)输入框内的文本

<html>
<body>
The Box:<input type="text" id="thebox" value="" size=10>
<br><input type="button" value="What's in the booooox?" onclick="document.getElementById('thebox').innerHTML='head of gwyneth paltrow';">
</body>
</html>

盒子:


顾名思义,innerHTML是指元素的HTML内容。您需要使用
value

The Box:<input type="text" id="thebox" value="" size=10>
<br><input type="button" value="What's in the booooox?" onclick="document.getElementById('thebox').value='head of gwyneth paltrow';">
框:


innerHTML
更改为
value