10
0

6_DOM事件绑定.html 715 B

12345678910111213141516171819202122232425262728
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <h1>hello</h1>
  10. <h1>world</h1>
  11. <script>
  12. var oH1 = document.getElementsByTagName("h1");
  13. // 鼠标点击事件(单击)
  14. oH1[0].onclick = function(){
  15. // console.log("hello world")
  16. // oH1[0].innerText = "你好";
  17. this.innerText = "hello world";
  18. }
  19. var oBody = document.getElementsByTagName("body")[0];
  20. oBody.oncontextmenu = function(){
  21. console.log("hello");
  22. return false;
  23. }
  24. </script>
  25. </body>
  26. </html>