http://jsfiddle.net/wDddR/3/

var input = document.createElement("input");
input.onclick = function (ev) {
    console.log(ev.timeStamp === 0 ? "WHY IS IT ZERO" : "It's not broken");
};
input.click()

var ev = document.createEvent("Event");
console.log(ev.timeStamp === 0 ? "THIS IS MADNESS" : "At least this works");

In firefox the first timeStamp is 0 and in chrome the timestamp is a sensible number.

In both firefox and chrome the second timeStamp is a sensible number.

有帮助吗?

解决方案

http://api.jquery.com/event.timeStamp/

Note: Due to a bug open since 2004, this value is not populated correctly in Firefox and it is not possible to know the time the event was created in that browser.

Bug #238041 - nsDOMEvent::AllocateEvent assigns a PR_Now() into a PRUint32

其他提示

The W3C specification states:

Used to specify the time (in milliseconds relative to the epoch) at which the event was created. Due to the fact that some systems may not provide this information the value of timeStamp may be not available for all events. When not available, a value of 0 will be returned.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top