Module calls a function from other module for registering and de-registering events on elements. I'm passing eventType as an argument. But getting an error Uncaught TypeError: elementObject.element.EventOption is not a function
模块从其他模块调用函数来注册和取消注册元素上的事件。我将eventType作为参数传递。但是获取错误Uncaught TypeError:elementObject.element.EventOption不是一个函数
elementObject = { element: document.getElementById("elemId"),... }
eventRegisterer(elementObject, addEventListener)
Function for event registration:
事件登记功能:
function eventRegisterer(elementObject, EventOption){
elementObject.element.EventOption('change', changeFunction)
}
function changeFunction() {
....
}
Why is that storing addEventListener
as argument is not working?
为什么存储addEventListener作为参数不起作用?
1 个解决方案
#1
0
Found the solution:
找到解决方案:
function eventRegisterer(elementObject, EventOption){
elementObject.element[EventOption('change', changeFunction)];
}
Using array-like notation instead of directly using property name did work.
使用类似数组的表示法而不是直接使用属性名称确实有效。
#1
0
Found the solution:
找到解决方案:
function eventRegisterer(elementObject, EventOption){
elementObject.element[EventOption('change', changeFunction)];
}
Using array-like notation instead of directly using property name did work.
使用类似数组的表示法而不是直接使用属性名称确实有效。