【发布时间】:2016-07-25 11:19:00
【问题描述】:
我正在使用Mutation Observer 来收听新添加的元素,它对所有元素都可以正常工作,但对于Switchery jQuery 插件却没有,因为 Switchery 通过 [document.querySelector] 获取元素
这是我的代码...
MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
var observerjQueryPlugins = function (repeaterWrapper) {
_.each(repeaterWrapper, function (repeaterItem, index) {
var jq_nodes = $(repeaterItem.addedNodes);
jq_nodes.each(function () {
// Color Picker (Working Good)
$(this).find('.element-wrapper.element-wpcolor .color-picker').wpColorPicker();
// Switchery using document.querySelector and i need to know the
// equivalent way to do it inside this loop .. like that
// Of course this code is WRONG
sw_current = $(this).find('.switchery-element');
var switchery = new Switchery( sw_current, {
disabled: false,
size: '',
color: '#8ce196',
secondaryColor: '#ddd',
jackColor: '#fff',
jackSecondaryColor: '#fff'
});
});
});
}
new MutationObserver(observerjQueryPlugins).observe(document.body, {
childList: true,
subtree: true,
attributes: false,
characterData: false
});
感谢您的帮助。
【问题讨论】:
标签: jquery-selectors mutation-observers switchery