문제

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