我想要使用奇妙的jQuery插件来编辑一堆选择框:https://github.com/indrimuska/jquery-editable-select。'映射'jquery插件功能到多个DOM元素
第一步是获取所有选择框的ID。我能够获得帮助Build an array of ids of all select boxes获得适用的选择框ID列表。
现在我需要将jquery插件函数映射到id数组。使用插件的基本命令是:
$('#editable-select').editableSelect();
我已经试过:
var test = [];
$("select").each(function() {
test.push($(this).attr('id'))
});
$("select").each(function() {
test.push($(this).attr('id'))
});
test.each(function() {
$(this).editableSelect();
});
我怎样才能“地图”插件功能的适当选择框的DOM元素?
test.each不是一个函数。你可以使用test.forEach()。另外,我建议你使用参数来获得你的元素。像:'test.forEach(function(el){el.editableSelect();});' 另外,为什么你有相同的代码2次'$(“select”)。each(func ....'? – rm4
如果你不想重用你的数组,我认为'$(“select”).editableSelect()'可以工作。我不知道这个插件,但通常,当你从jquery调用一个函数时,它 – rm4
对不起,没有工作,基于http://indrimuska.github.io/jquery-editable-select/,似乎需要一个id来选择 – user61629