【问题标题】:How to get onclick button to show text in input box如何让onclick按钮在输入框中显示文本
【发布时间】:2013-11-03 21:42:52
【问题描述】:

我在使用更复杂的代码块时遇到了这个问题,所以我开始在电影 The Seven 中使用 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更改为value

标签: html button input onclick


【解决方案1】:

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';">

See it in action

【讨论】:

    猜你喜欢
    • 2016-03-24
    • 1970-01-01
    • 1970-01-01
    • 2016-04-16
    • 1970-01-01
    • 1970-01-01
    • 2020-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多