我想将一个事件绑定到选择元素,其中每个选择元素都将其转换为一个jquery-selectbox元素(https://github.com/marcj/jquery-selectBox)var selectBoxes = [];var selectElements = [];$('.select').each(function (index, element) { //Instantiates selectbox plugin (https://github.com/marcj/jquery-selectBox) selectBoxes[index] = new SelectBox($(element), settings = {}); selectElements[index] = selectBoxes[index].getSelectElement(); //gets the particular select element //Binding a close event to perform some tasks $(selectElements[index]).bind('close', function (el) { //Doing something here });});添加一个插件:https ://plnkr.co/edit/L3dwtVl4rjn2BKBe43x5 ? p = preview当我在选择框中选择一个选项时,上面绑定的jquery事件将触发那里存在的许多select元素。就我而言,我有3个选择元素,因此触发了三次。
2 回答

月关宝盒
TA贡献1772条经验 获得超5个赞
根据插件文档,您使此过程变得过于复杂
尝试更换所有东西
$('select').selectBox(/* options*/).close(function () {
alert($(this).val());
});
请注意,该插件似乎没有维护很长时间
添加回答
举报
0/150
提交
取消