Event.timeStamp
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
說明
回傳事件建立的時間(單位是毫秒;從 epoch 開始計算)。
Syntax
event.timeStamp
範例
var number = event.timeStamp;
下面是一個較為完整的範例:
html
<html>
<head>
<title>timeStamp example</title>
<script type="text/javascript">
function getTime(event) {
document.getElementById("time").firstChild.nodeValue = event.timeStamp;
}
</script>
</head>
<body onkeypress="getTime(event)">
<p>Press any key to get the current timestamp for the onkeypress event.</p>
<p>timeStamp: <span id="time">-</span></p>
</body>
</html>
注意
這個 property 僅在瀏覽器支持該事件才會有用。