alert
和 confirm
是浏览器网页中内置 函数
,主要是通过弹窗来提示用户, 是 JavaScript
代码getElementById
函数,这个函数 JavaScript
通过元素 id 属性的值
,获取这个元素对象,然后进行操作即可。这个在前面的 JavaScript 课程中有讲新建 html 文件 19-alert.html
,编写下方程序,运行看看效果吧。
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<title>alert 和 confirm</title>
</head>
<body>
<buttononclick="doDelete(1)">删除数据</button>
<inputid="myinput">
<buttononclick="doGet()">取出myinput中的输入数据</button>
<scripttype="text/javascript">
// alert('这是提示')
function doDelete(id){
if(confirm("是否删除id="+id+"的这条数据?")){
alert('你点了确定删除')
}else{
alert('你点了取消删除')
}
}
function doGet(){
//取出input里面的值
let value = document.getElementById("myinput").value
alert(value)
}
</script>
</body>
</html>
```
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有