javascript - 3 个按钮上的 Javascript 警报
问题描述
我是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
解决方案
document.getElementById('alert').addEventListener('click', function() {
alert('Hello World');
});
document.getElementById('confirm').addEventListener('click', function() {
confirm('Are you sure?');
});
document.getElementById('prompt').addEventListener('click', function() {
prompt('Enter your name');
});
<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>
推荐阅读
- flutter - 除非使用 Center 包装小部件,否则 Flutter 设置容器小部件的宽度和高度不起作用?为什么?
- javascript - 使用 Bootstrap 3.3 更改打印行顺序
- postgresql - 具有多列索引的 postgres 查询的执行时间很慢
- javascript - 嵌入表单并将其发布到另一个站点
- django - AttributeError:模块“django.db.models”没有属性“级联”
- angular - 为什么 Firebase Deploy 刚刚找到 1-2 个文件?只是 Firebase 托管的默认索引
- java - 在 Pub-Sub 模型中跟踪请求的开始和结束 - 问题
- c - 在 yacc 中返回指针时出现分段错误
- javascript - 如何在输入字段上获取数组值
- php - MercadoLibre API 给出错误“getAuthUrl() 不应被静态调用”