fengchuanyu 9 mēneši atpakaļ
vecāks
revīzija
05b7b462bb
1 mainītis faili ar 21 papildinājumiem un 8 dzēšanām
  1. 21 8
      4_DOM&BOM/14_DOM绑定事件2.html

+ 21 - 8
4_DOM&BOM/14_DOM绑定事件2.html

@@ -4,12 +4,24 @@
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <title>Document</title>
+    <style>
+        .box{
+            position: fixed;
+            top:200px;
+            left: 100px;
+            background-color: red;
+        }
+    </style>
 </head>
 <body>
     <div class="box">hello</div>
     <script>
         var oBox = document.getElementsByClassName("box")[0];
         
+        oBox.onclick = function(){
+            console.log(oBox.offsetLeft);
+            console.log(oBox.offsetTop);
+        }
         // function foo(){
         //     console.log("click");
         //     // removeEventListener 移除事件 接受两个参数 第一个事件名称,第二个是事件处理函数(绑定和移除的必须是同一个函数,用匿名函数不可以)
@@ -62,15 +74,16 @@
         //     })
         // })
 
-        oHtml.onmousedown = function(){
-            oHtml.onmousemove = function(e){
-                console.log(e.clientX,e.clientY)
-            }
-            oHtml.onmouseup = function(){
-                oHtml.onmousemove = null;
-            }
-        }
+        // oHtml.onmousedown = function(){
+        //     oHtml.onmousemove = function(e){
+        //         console.log(e.clientX,e.clientY)
+        //     }
+        //     oHtml.onmouseup = function(){
+        //         oHtml.onmousemove = null;
+        //     }
+        // }
 
+        
 
     </script>
 </body>