javascript - selObj.fireEvent 不是函数
问题描述
当用户单击父项时,我们在 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>
我们得到了这个: Uncaught TypeError: selObj.fireEvent is not a function
它曾经可以在较旧的浏览器版本上运行(我认为是 explorer 8),但现在不再使用 Chrome。任何想法为什么?
解决方案
fireEvent 方法是一种专有的 Microsoft Internet Explorer 替代标准 EventTarget.dispatchEvent() 方法。
请改用 dispatchEvent 方法。
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent
推荐阅读
- video - 使用 ffmpeg 压缩视频
- node.js - AWS Lambda 中的 Sequelize 错误“sequelize.authenticate(...).then(...).catch(...).done 不是函数”
- mongodb - MongoDB 计算唯一属性
- r - 抛硬币概率(已解决)
- javascript - 带有自定义音频播放器的多种声音
- github - 如果检查和 Teamcity 构建失败,如何禁止代码合并?
- go - 如何在 Go 的 PostgreSQL 列中为自定义类型编写 Scan()
- vite - vite 构建总是使用静态路径
- jenkins - 通过 Web 应用程序执行远程 SSH 的最佳方式是什么
- blockchain - 如何将以太坊虚拟机集成到我的区块链中