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

javascript實(shí)時(shí)獲取鼠標(biāo)坐標(biāo)值并顯示的方法

 更新時(shí)間:2015年04月30日 10:11:46   作者:休閑生活文化  
這篇文章主要介紹了javascript實(shí)時(shí)獲取鼠標(biāo)坐標(biāo)值并顯示的方法,涉及javascript操作鼠標(biāo)事件的相關(guān)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

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

<!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=gb2312" />
<title>JS實(shí)時(shí)獲取鼠標(biāo)坐標(biāo)值并顯示</title>
</head>
<body>
<script type="text/javascript">
 var getCoordInDocumentExample = function(){
  var coords = document.getElementById("coords");
  coords.onmousemove = function(e){
   var pointer = getCoordInDocument(e);
   var coord = document.getElementById("coord");
   coord.innerHTML = "X,Y=("+pointer.x+", "+pointer.y+")";
  }
 }
 var getCoordInDocument = function(e) {
  e = e || window.event;
  var x = e.pageX || (e.clientX +
   (document.documentElement.scrollLeft
   || document.body.scrollLeft));
  var y= e.pageY || (e.clientY +
   (document.documentElement.scrollTop
   || document.body.scrollTop));
  return {'x':x,'y':y};
 }
 window.onload = function(){
   getCoordInDocumentExample();
 };
</script>
<div id="coords" 
style="width:500px;height:200px;background:#F2F1D7;
border:2px solid #0066cc;">
請(qǐng)?jiān)诖艘苿?dòng)鼠標(biāo)。
</div>
<br />
<div id="coord" 
style="width:500px;border:2px solid #336699;">&nbsp;</div>
</body>
</html>

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

相關(guān)文章

最新評(píng)論