欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript獲取當(dāng)前鼠標(biāo)坐標(biāo)的方法

 更新時(shí)間:2015年01月10日 11:48:08   投稿:shichen2014  
這篇文章主要介紹了javascript獲取當(dāng)前鼠標(biāo)坐標(biāo)的方法,可針對不同瀏覽器獲取鼠標(biāo)的坐標(biāo)位置,是非常實(shí)用技巧,需要的朋友可以參考下

本文實(shí)例講述了javascript獲取當(dāng)前鼠標(biāo)坐標(biāo)的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

對于javascript獲取當(dāng)前鼠標(biāo)坐標(biāo)來說,得對不同瀏覽器的坐標(biāo)位置有所了解。具體代碼如下:

復(fù)制代碼 代碼如下:
<html>
<head>
<title>javascript獲取當(dāng)前鼠標(biāo)坐標(biāo)</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<script type="text/javascript">
 function mousePosition(ev){
  if(ev.pageX || ev.pageY){//firefox、chrome等瀏覽器
   return {x:ev.pageX,y:ev.pageY};
  }
  return {// IE瀏覽器
   x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
   y:ev.clientY + document.body.scrollTop - document.body.clientTop
  };
 }
 function mouseMove(ev){
  ev = ev || window.event;
  var mousePos = mousePosition(ev);
  document.getElementById('x').innerHTML = mousePos.x;
  document.getElementById('y').innerHTML = mousePos.y;
 }
 document.onmousemove = mouseMove;
</script>
<style type="text/css">
h3{color:blue;}
p{line-height:30px;height:30px;font-size:14px;width:500px;}
span{color:orange;font-weight:bold;}
</style>
</head>
<body>
 <h3>您的鼠標(biāo)已經(jīng)被跟蹤</h3>
 <p> X 軸坐標(biāo):<span id="x"></span></p>
 <p> Y 軸坐標(biāo):<span id="y"></span></p>
</body>
</html>

希望本文所述對大家的javascript程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論