Firefox 6 的 Event.target 问题
在 Firefox 6 中,我尝试获取发生事件的目标元素,但它没有显示任何元素,并且在警报中显示未定义。尝试使用 Firebug 工具对其进行调试,发现事件对象缺少属性“target”。有人可以帮我吗?我确实有下面的代码:
function getSource(event)
{
if(!event)
{
field = window.event.srcElement;
alert(field);
}
else
{
field = event.target;
alert(field) //Getting undefined in FF6
}
}
编辑部分:
document.onkeypress = getSource;
document.onmouseup = getSource;
任何帮助将不胜感激。
In Firefox 6 I tried to get the target element on which the event occurred, but it does not show any element and it shows undefined in alert. Tried to debug it using the Firebug tool and found the attribute "target" missing for the event object. Can anyone help me out? I do have the code below:
function getSource(event)
{
if(!event)
{
field = window.event.srcElement;
alert(field);
}
else
{
field = event.target;
alert(field) //Getting undefined in FF6
}
}
Edited Portion:
document.onkeypress = getSource;
document.onmouseup = getSource;
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试下面的代码
希望这对您有帮助。
Try the code below
Hope this helps you.
在 Fx 6 中测试这一点:
它应该提醒“P”。
Test this in Fx 6:
It should alert "P".
正如类似问题中所解释的,将函数更改为:
As also explained in the similar question, change the function to this: