我想知道是否有任何已確定的方法來解決與DOM事件的瀏覽器不一致問題。 修復事件的最佳方法是什麼?修復本機Javascript事件
下面是我現在玩的東西(雖然還是壞了)。
Event.prototype.fix = function()
{
//if (! event) var event = window.event;
// Fix target property, if necessary (IE 6/7/8 & Safari2)
if (! this.target)
{
this.target = this.srcElement || document;
}
// Target should not be a text node (Safari)
if (this.target.nodeType === 3)
{
this.target = event.target.parentNode;
}
// Add which for key events
if (this.which == null)
{
this.which = this.charCode != null ? this.charCode : this.keyCode;
}
// For mouse/key events; add metaKey if it's not there (#3368, IE6/7/8)
if (this.metaKey === undefined)
{
this.metaKey = this.ctrlKey;
}
this.posx = 0;
this.posy = 0;
if (this.pageX || this.pageY)
{
this.posx = this.pageX;
this.posy = this.pageY;
}
else if (this.clientX || this.clientY)
{
this.posx = this.clientX + document.body.scrollLeft
+ document.documentElement.scrollLeft;
this.posy = this.clientY + document.body.scrollTop
+ document.documentElement.scrollTop;
}
};
還發現了一個類似的功能[相關問題](http://stackoverflow.com/questions/4643249/cross-browser-event-object-normalization)。 – Xeoncross