55 lines
1.2 KiB
HTML
55 lines
1.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
<title>js 事件</title>
|
|
</head>
|
|
<body>
|
|
|
|
|
|
|
|
<!-- <button onclick="buttonClick()" >点我</button> -->
|
|
<button>点我</button>
|
|
|
|
|
|
<script>
|
|
|
|
// 第一种定义事件的方法
|
|
// 不好的地方:
|
|
// function buttonClick() {
|
|
// alert("不要点我")
|
|
// }
|
|
|
|
// 第二种定义事件的方法
|
|
//
|
|
// document.querySelector("button").onclick = function () {
|
|
// document.querySelector("button").innerText = "不要点我1";
|
|
// }
|
|
|
|
|
|
// 第三种定义事件的方法
|
|
// document.querySelector("button").addEventListener("click",function(){
|
|
// alert(1)
|
|
// })
|
|
// document.querySelector("button").addEventListener("click",function(){
|
|
// alert(2)
|
|
// })
|
|
|
|
// 使用js获取元素的几种方法
|
|
// document.getElementById
|
|
// document.getElementsByClassName
|
|
// document.getElementsByTagName
|
|
// document.getElementsByName
|
|
// document.querySelector(".name p");
|
|
// document.querySelectorAll(".name p");
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</body>
|
|
</html> |