Files
ClassContent/历届学生/font-end-nine/每天上课/2022-06-13/事件.html
2024-09-27 02:06:13 +08:00

98 lines
2.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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>事件</title>
</head>
<body>
<button class="one">点我</button>
<button class="two" onclick="test()">哈哈哈</button>
<button class="three" >哈哈哈22333</button>
<a href="https://www.baidu.com/">百度</a>
</body>
<script>
// 事件
// 事件有三要素
// 事件源 事件类型 事件处理函数
// 事件冒泡
var a = document.querySelector(".one")
// a.innerHTML = "<span>你好</span>"
console.dir(a);
document.querySelector("a").onclick = function (e) {
// 阻止默认事件
e.preventDefault();
console.log("hahaah");
}
a.onclick = function (event) {
console.log(event);
alert("点我干什么1")
}
// function test() {
// alert("two")
// }
// document.querySelector(".three").addEventListener('click', function() {
// alert("哈哈哈1")
// })
// document.querySelector(".three").addEventListener('click', function() {
// alert("哈哈哈2")
// })
// var dom = {
// tagName: 'div',
// className: 'main',
// idName: null,
// children: [
// {
// tagName: 'h2',
// className: 'title',
// idName: null,
// children: [
// {
// tagName: 'img',
// className: null,
// idName: null,
// children: null
// }
// ]
// },
// {
// tagName: 'button',
// className: null,
// idName: null,
// children: [
// {
// tagName: '#text',
// className: null,
// idName: null,
// children: null
// }
// ]
// }
// ]
// }
// 虚拟domjs对象
// 影子dom
// 真实dom
</script>
</html>