知识总结:
<pre>
event对象:
获取鼠标坐标:
使用的是event对象,此对象中有两个属性记录鼠标实时移动的横纵坐标
火狐:pageX,pageY
ie:x,y
获取键盘值:
获取event对象:var eve=eve||window.event;
获取键盘值:var keycode=eve.keyCode;
</pre>
代码示例:
<pre>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
function mykey(eve){
var eve=eve||window.event;
var keycode=eve.keyCode;
var mysp=document.getElementById("myspan");
mysp.innerHTML=keycode;
}
function myxy(eve){
var eve=eve||window.event;
var x=eve.x||eve.pageX;
var y=eve.y||eve.pageY;
var loc=x+":"+y;
var mys=document.getElementById("myspan01");
mys.innerHTML=loc;
}
</script>
<style type="text/css">
#mydiv{
border: solid 1px;
width: 200px;
height: 200px;
background-color: blanchedalmond;
}
</style>
</head>
<body>
<input type="text" name="" id="" value="" onkeyup="mykey(event);"/>
<span id="myspan">
</span>
<div id="mydiv" onmousemove="myxy(event);">
</div>
<span id="myspan01">
</span>
</body>
</html>
</pre>