| <! DOCTYPE html> <Html> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/> <Script src = "// ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </script> <Title> jquery obtains the coordinates of the mouse pointer </title> <Script> // Common js Functions Function test (event ){ Event = event | window. event; Var x = event. offsetX | event. layerX; Var y = event. offsetY | event. layerY; Alert ("x =" + x + "; y =" + y ); } // Jquery Function $ (Function (){ $ ("# T"). mouseover ( Function (event ){ Event = event | window. event; Var x = event. offsetX | event. originalEvent. layerX; Var y = event. offsetY | event. originalEvent. layerY; Alert ("x:" + x + "; y:" + y ); } ); }); </Script> </Head> <Body> <Div id = "t" style = "float: left; background-color: green; width: 300px; height: 60px;"> test the mouse position (jquery function processing) </div> <Div id = "s" onmouseover = "test (event)" style = "float: left; background-color: red; width: 300px; height: 60px; margin-left: 10px; "> test the mouse position (Common js function processing) </div> </Body> </Html> |