在 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;
如有任何帮助,我们将不胜感激。
最佳答案
试试下面的代码
function getSource(e)
{
if(!e)
e = window.event;
field = evt.srcElement || evt.target;
alert(field);
return true;
}
希望对你有帮助。
关于javascript - Firefox 6 的 Event.target 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7565118/