<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button>点击</button>
<script>
// 元素对象.addEventListener('事件类型' , 要执行的函数 )
// 需求:点击按钮,弹出一个对话框
// 1.事件源 按钮
const btn = document.querySelector('button')
// 2.事件类型 点击鼠标 click 字符串
btn.addEventListener('click',function(){
alert('你好')
})
</script>
</body>
</html>
01-事件监听
最新推荐文章于 2024-07-18 11:48:33 发布