123456789101112131415161718192021222324252627282930313233343536373839 |
- <!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>
- <h1>hello</h1>
- <h1>world</h1>
- <script>
- var oH1 = document.getElementsByTagName("h1");
- // 鼠标点击事件(单击)
- oH1[0].onclick = function(){
- // console.log("hello world")
- // oH1[0].innerText = "你好";
- this.innerText = "hello world";
- }
- // 鼠标右键
- var oBody = document.getElementsByTagName("body")[0];
- oBody.oncontextmenu = function(){
- console.log("hello");
- // return false 在事件处理函数当中可以阻止浏览器的默认行为
- return false;
- }
- // 鼠标滑入
- // 鼠标移入滑动时频繁触发
- // oH1[1].onmousemove = function(){
- // console.log("mouseover")
- // }
- // 鼠标移入仅触发一次
- // oH1[1].onmouseenter = function(){
- // console.log("mouseenter")
- // }
- </script>
- </body>
- </html>
|