为了账号安全,请及时绑定邮箱和手机立即绑定

jQuery事件附加到对象数组

jQuery事件附加到对象数组

慕标琳琳 2021-04-19 10:14:11
我想将一个事件绑定到选择元素,其中每个选择元素都将其转换为一个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());

});

请注意,该插件似乎没有维护很长时间


查看完整回答
反对 回复 2021-04-29
  • 2 回答
  • 0 关注
  • 141 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信