事件兼容性

xiaoxiao2021-02-28  149

<!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Document</title> <style type="text/css"> *{ margin: 0px; padding: 0px; } #box{ width: 600px; height: 600px; background: pink; margin-left: 100px; margin-top: 100px; position: absolute; } </style> <script type="text/javascript"> window.onload = function(){ var box = document.getElementById("box"); box.onmousemove = function(e){ var e = e || window.event; //判断ie和非ie的获取事件的方法 var left = e.layerX || e.offsetX; //判断是ie和非ie距离事件源的方法 var top = e.layerY || e.offsetY; document.title = left + '|' + top; } } </script> </head> <body> <div id="box"> </div> </body> </html>
转载请注明原文地址: https://www.6miu.com/read-40417.html

最新回复(0)