IE e.target.id 不工作 [英] IE e.target.id is not working
本文介绍了IE e.target.id 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
document.click = check;
function check(e)
{
var obj = document.getElementById('calendar_widget');
if (obj != 'null')
{
if (e.target.id != 'show_calender')
obj.style.display='none';
}
}
Internet Explorer 中的错误:e.target.id 未定义.
Error is in Internet Explorer: e.target.id is undefined.
推荐答案
IE 不支持 target 属性,他们使用 srcElement 代替.
IE doesn't support the target property, they use srcElement instead.
变化:
if (e.target.id != 'show_calender')
到:
if ((e.target || e.srcElement).id != 'show_calender')
您可能还需要将其添加到函数的开头:
You may also need to add this to the beginning of your function:
if (!e) e = window.event
您的最终代码如下所示:
Your final code would look like this:
function check(e) {
if (!e) e = window.event;
var obj = document.getElementById('calendar_widget');
if (obj != 'null') {
if ((e.target || e.srcElement).id != 'show_calender')
obj.style.display='none';
}
}
这篇关于IE e.target.id 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文