用js代码取得鼠标的实时坐标,听起来蛮激动人心的,以下代码,将带你走进这般的奇妙世界,哈!!!
代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>获取鼠标的实时坐标-www.jb200.com</title> <style type="text/css"> #top_div{ position:absolute; width:100PX; height:50px; border:1px solid #00F; text-align:center; color:blue; } </style> <script type="text/javascript" src="/js/jquery-1.6.1.min.js"></script> <script type="text/javascript"> function initMouseMove(){ document.onmousemove = function (e){ x = document.documentElement.scrollLeft+e.clientX; y = document.documentElement.scrollTop+e.clientY; $("#top_div").html("当前坐标 X:"+x+"Y:"+y); $("#top_div").css("left",x); $("#top_div").css("top",y); }} </script> </head> <body onload="initMouseMove()"> <div id="top_div"></div> </body> </html>