Sco*_*ers 5 javascript jquery events
我有一个表,当用户点击每个单元格时,一些细节应出现在用户单击的小弹出框中.我正在使用JQuery,但不是将函数绑定到onclick事件.
function detailPopup(cell, event, groupName, groupID, ...)
{
var newDiv = document.createElement("div");
newDiv.id = "detailPop" + groupID;
newDiv.className = "priceDetailPopup";
newDiv.innerHTML = "<p>" + groupName + "</p>"; // more will go here
$(newDiv).click(function()
{
$(this).fadeOut("fast").remove();
}
);
$("#main").append(newDiv);
$(newDiv).css({"left" : event.pageX, "top" : event.pageY}).fadeIn("fast");
}
Run Code Online (Sandbox Code Playgroud)
在FF,Safari和Chrome中,一切都非常出色.在IE中,除了细节div出现在表格下方之外,它都有效.event.pageX/Y不起作用.我知道如果我通过JQuery绑定函数,JQuery将为IE修复这些:
$(cell).click(function(e) { ... e.pageX ... })
Run Code Online (Sandbox Code Playgroud)
但我不能这样做.(我认为我不能 - 如果你这样做,请解释如何在不使用单元格中的非xhtml标签的情况下将六个变量放入该函数中.)
有没有办法让JQuery"修复"事件对象而不通过JQuery绑定函数?$ JQuery.fixEvent(事件); 或者其他的东西?我在他们的网站上找不到任何参考.
提前谢谢了.
Jos*_*ola 12
e = jQuery.event.fix(e); //you should rename your event parameter to "e"
Run Code Online (Sandbox Code Playgroud)
我fix通过搜索jQuery源代码找到了该函数.
或者,您可以使用它来获取没有 jQuery 的鼠标坐标...
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
}
else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
}
Run Code Online (Sandbox Code Playgroud)
通过PPK:http://www.quirksmode.org/js/events_properties.html
| 归档时间: |
|
| 查看次数: |
8695 次 |
| 最近记录: |