我想將一個(gè)事件綁定到選擇元素,其中每個(gè)選擇元素都將其轉(zhuǎn)換為一個(gè)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 });});添加一個(gè)插件:https ://plnkr.co/edit/L3dwtVl4rjn2BKBe43x5 ? p = preview當(dāng)我在選擇框中選擇一個(gè)選項(xiàng)時(shí),上面綁定的jquery事件將觸發(fā)那里存在的許多select元素。就我而言,我有3個(gè)選擇元素,因此觸發(fā)了三次。
jQuery事件附加到對(duì)象數(shù)組
慕標(biāo)琳琳
2021-04-19 10:14:11