问题描述
我们在一个 js 文件上有这个函数,当用户点击父项时拉出一个菜单树:
function menusel(unid)
{
//if its in the array,deactivate it and take it out
var index = inarray(unid,selectedarray);
//first arrange the array
if(index)
{
selectedarray[index] = 0;
}
else
{
//we have restrictions
if(treeRestrictMode==1)
{
//Now check its not in the array of items not allowed to b picked
if(inarray(unid,nonSelArr))
{
alert('This Item is Unselectable');
return;
}
}
//if we are in unique tree mode,can only select one
if(treeSingleMode==1)
{
//check for a non zero value,and deselect it [recursively]#
for(var x=0;x<selectedarray.length;x++)
{
if(selectedarray[x]!=0)
{
//alert(unid+' '+selectedarray[x]);
menusel(selectedarray[x]);
}
}
}
selectedarray.push(unid);
}
sel_unselect(unid,index);
//if we have an override function,it means we will assume that the parent page
//as an input type function called treeSelFunc which takes the id and takes care of the rest
if(overridefunction!='')
{
parent.parent.treeSelFunc(unid,selName);
return;
}
if(treeSingleMode!=1)
{
var selObj = emptySel(0);//set txt will fill it for us
}
else
{
var selObj = parent.parent.MM_findobj(selName);
//see if we have options..will need to empty them
if(selObj.size>1)
{
emptySel(1);
}
else
{
selObj.value=0;
}
}
setTxt(selObj);
selObj.fireEvent('onchange');
}
我们在页面上这样称呼它:
<a id="troot[VMENU]_040" onclick="menusel(40);" class="sel">All</a>
我们得到了这个: 未捕获的类型错误:selObj.fireEvent 不是函数
它曾经可以在较旧的浏览器版本上运行(我认为使用资源管理器 8),但现在不再使用 Chrome 了。任何想法为什么?
解决方法
fireEvent 方法是标准 EventTarget.dispatchEvent() 方法的专有 Microsoft Internet Explorer 替代方法。
改用 dispatchEvent 方法。
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent