【发布时间】:2018-08-24 14:57:01
【问题描述】:
我正在尝试创建另一种扩展 $.event.special 对象的事件类型。因为我需要更改与输入类型不同的元素。问题是当我启动页面时控制台给了我这个错误:
main.js:5 Uncaught TypeError: Cannot read property 'mutationsLists' of undefined
脚本是这样的:
(function($){
$.event.special.changeElement = {
eventType: 'changeElement',
mutationObserver : new MutationObserver($.event.special.changeElement.mutationsLists),
setup: function(data, namespaces) {
var config = { attributes: true, childList: true };
$.event.special.changeElement.mutationObserver.observe(this, config);
},
teardown: function(namespaces) {
$.event.special.changeElement.mutationObserver.disconnect();
},
handler: function(event) {
event.type = $.event.special.changeElement.eventType;
return $.event.dispatch.apply(this, arguments);
},
mutationsLists : function(mutationsList) {
for(var mutation of mutationsList) {
if (mutation.type == 'childList') {
console.log('A child node has been added or removed.');
}
else if (mutation.type == 'attributes') {
console.log('The ' + mutation.attributeName + ' attribute was modified.');
}
}
}
}
})(jQuery);
我检查了一下,它看起来 $.event.special.changeElement 已定义,但在调用其成员时看起来未定义...
【问题讨论】:
标签: jquery function events plugins undefined