我看到两件事,将您的点击事件更改为:
coordinates.onclick = function(event) {
event = event || window.event;
if (!window.event) { // thanks firefox
event.offsetX = event.layerX;
event.offsetY = event.layerY;
}
seatsArray.push(event.offsetX, event.offsetY);
}
Firefox offsetX/Y 是layerX/Y,即有一个全局事件对象。
但是,如果您没有全局坐标,请尝试以下操作:
coordinates.onclick = function(e) {
e = e || window.event;
if (e && e.pageX && e.pageY) {
e.posX = e.pageX;
e.posY = e.pageY;
} else if (e && e.clientX && e.clientY) {
var scr = {x:0,y:0},
object = e.srcElement || e.target;
//legendary get scrolled
for (;object.parentNode;object = object.parentNode) {
scr['x'] += object.scrollLeft;
scr['y'] += object.scrollTop;
}
e.posX = e.clientX + scr.x;
e.posY = e.clientY + scr.y;
}
seatsArray.push(e.posX, e.posY);
}