我在输入字段上使用Select2作为多选。我试图找出正在被点击的选项,但如果我查看点击选项(“选择选择”)时发生的事件,我只能找到event.target.value,它是包含所有选定选项的数据数组(选择)。基本上我想访问点击的值,所以我可以让用户在该特定选项中编辑自定义属性。我怎么能这样做呢?在Select2倍数中获取/设置点击选择的值
的jsfiddle问题:http://jsfiddle.net/JtTTF/
$(test).bind("choice-selected", function(e) {
alert(e.target.value);
// this is where i would like to access the clicked choice id so i can edit the custom data attribute "reason"
});
您的解决方案完美无缺。非常感谢! –
您能否分享一下您使用的Select2版本来实现?在当前文档中,我找不到任何选择选择的事件:http://ivaynberg.github.io/select2/#documentation – Marklar
@Marklar,你找到答案了。我也没有找到选择选择的事件。大卫你使用哪个版本? – Erlan