我正在尝试在Internet Explorer javascript中替换attachEvent。
ptIn = document.Form1.pt;
if (ptIn.attachEvent){
ptIn.attachEvent("BeforeContextMenu", pivotBeforeContextMenu);
ptIn.attachEvent("CommandExecute", pivotCommandExecute);
}else{
alert("Running IE11 or IE9");
ptIn.addEventListener("BeforeContextMenu(ix, iy, mnu, cancel)", pivotBeforeContextMenu,false);
ptIn.addEventListener("CommandExecute(vCommand, fSucceeded)", pivotCommandExecute,false);
ptIn.addEventListener("BeforeContextMenu", pivotBeforeContextMenu,false);
ptIn.addEventListener("CommandExecute", pivotCommandExecute,false);
ptIn.BeforeContextMenu = pivotBeforeContextMenu;
ptIn.CommandExecute = pivotCommandExecute;
}
我甚至试过命名函数pt_BeforeContextMenu。
唯一可行的方法是创建一个脚本标记:<script language="javascript" event="BeforeContextMenu(ix, iy, mnu, cancel)" for="pt">
有没有更好的方法来完成将函数附加到事件?
注意:
ptIn.attachEvent(....)有效,但不再在IE11中。
我正在尝试使用的事件:https://msdn.microsoft.com/en-us/library/aa193082(v=office.11).aspx
function pivotBeforeContextMenu(iX, iY, mnu, fCancel){ //does stuff }
function pivotCommandExecute(vCommand, fSucceeded){ //does stuff }