我正在尝试制作一个测试你的反应时间的程序,但我不知道如何测量两个事件之间的时间,比如按钮点击.到目前为止,这是我的代码.提前感谢任何可以提供帮助的人.
Barmar.. 7
var startTime; function startButton() { startTime = Date.now(); } function stopButton() { if (startTime) { var endTime = Date.now(); var difference = endTime - startTime; alert('Reaction time: ' + difference + ' ms'); startTime = null; } else { alert('Click the Start button first'); } }
将开始和停止按钮绑定到这些功能.
DEMO
var startTime; function startButton() { startTime = Date.now(); } function stopButton() { if (startTime) { var endTime = Date.now(); var difference = endTime - startTime; alert('Reaction time: ' + difference + ' ms'); startTime = null; } else { alert('Click the Start button first'); } }
将开始和停止按钮绑定到这些功能.
DEMO