【问题标题】:How to display message after onClick button clicked单击onClick按钮后如何显示消息
【发布时间】:2021-05-11 02:26:50
【问题描述】:

我的 onClick 按钮在我点击后已经运行了一个功能,我只是希望它在被点击后也显示一条确认消息。我只是卡住了。任何帮助都会得到帮助。 这就是我的按钮的格式:

<button id="button" type="button" onClick={write}> 
    RESERVE ROOM
  </button>

【问题讨论】:

  • write是你定义的函数吗?
  • 它是一个写有函数的常量

标签: javascript html button onclick


【解决方案1】:

只需创建一个将消息添加到 html 元素的写入函数

function write() {
  const message = document.getElementById("message");
  message.innerText = "This is the inserted message";
}

【讨论】:

  • 哪个元素的 id 为“message”?
  • 添加一个简单的元素&lt;div id="message"&gt;&lt;/div&gt;。这只是一个包含消息的标签。
  • 我不断收到此错误:“TypeError: Cannot set property 'innerText' of null”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-26
  • 2019-01-30
相关资源
最近更新 更多