|
|
@@ -0,0 +1,28 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<html lang="en">
|
|
|
+<head>
|
|
|
+ <meta charset="UTF-8">
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
+ <title>Document</title>
|
|
|
+</head>
|
|
|
+<body>
|
|
|
+ <button>按钮</button>
|
|
|
+ <script>
|
|
|
+ // 获取元素
|
|
|
+ var btn = document.getElementsByTagName("button")[0];
|
|
|
+ // 绑定事件
|
|
|
+ // 1、on绑定事件 需要绑定事件的标签.on事件名 = 事件函数;
|
|
|
+ // btn.onclick = function(){
|
|
|
+ // console.log("按钮被点击了");
|
|
|
+ // }
|
|
|
+
|
|
|
+ // 2、addEventListener()方法。需要绑定事件的标签.addEventListener("事件名,事件函数);
|
|
|
+ // btn.addEventListener("click",function(){})
|
|
|
+ btn.addEventListener("click",function(){
|
|
|
+ console.log("按钮被点击了");
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
+</html>
|