【发布时间】:2018-06-01 11:17:54
【问题描述】:
我是 Java 脚本的新手。我有 3 个按钮。
<button type="button" class="btn btn-primary m-1" id="alert">Alert!</button>
<button type="button" class="btn btn-success m-1" id="confirm">Confirm!</button>
<button type="button" class="btn btn-info m-1" id="prompt">Prompt!</button>
我需要在点击它们时弹出一个警报,所以对于第一个“警报”,它会是你好。第二个是确认您是否确定继续。最后一个是一个提示,只是其中的一个随机名称。
感谢所有答案! :D
【问题讨论】:
-
欢迎来到 Stack Overflow! StackOverflow 不是免费的编码服务。所以希望你try to solve your own problem first。请更新您的问题以在minimal reproducible example 中显示您已经尝试过的内容。如需更多信息,请参阅How to Ask,并拨打tour :)
-
添加事件处理程序的方法有很多。你可以在 HTML 中使用
onclick,你可以在 Javascript 中使用addEventListener(),你可以在 jQuery 中使用.on()。 -
如果您使用 Google,您会发现多个示例说明如何完成这项基本任务。
-
任何关于编写 Javascript Web 应用程序的教程都应该解释基础知识。
-
您可以访问 tizag.com 或 tutorialspoint.com 学习 JavaScript 的基础知识
标签: javascript html