日期:2014-05-16  浏览次数:20364 次

js之看你的鼠标点多快
<!DOCTYPE HTML> 
<html>
<head>
<script type="text/javascript" src="test/jquery-1.7.2.min.js"></script>
<script type="text/javascript">

$(document).ready(function(){
var last, diff;
$('div').click(function(event) {
  if ( last ) {
    diff = event.timeStamp - last
    $('div').append('time since last event: ' + diff + '<br/>');
  } else {
    $('div').append('Click again.<br/>');
  }
  last = event.timeStamp;
}); 
});
</script>
  <style type="text/css">
div { height: 100px; width: 300px; margin: 10px; 
      background-color: #ffd; overflow: auto; }
</style>
</head>
<body>
<div>Click.</div>
</body>
</html> 

上述代码中主要介绍了event对象的timeStamp(时间戳)这个对象

运行下后点击区域,会显示和上次点击的时间间隔,玩游戏的人可以测测你点击鼠标有多快哦