答案 0 :(得分:1)
您可以使用Select2的templateSelection选项,并为选项标记
添加一些自定义属性HTML:
<select id="long" class="js-example-basic-multiple" multiple="multiple">
<option data-custom="" value="all">All </option>
<option data-custom="Lorem ipsum" value="#FF0000">Lorem ipsum dolor sit amet consectetur adipiscing elit</option>
<option data-custom="Sed do" value="#00FF00">Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</option>
<option data-custom="Ut enim" value="#0000FF">Ut enim ad minim veniam quis nostrud exercitation</option>
<option data-custom="Duis aute" value="#FFFF00">Duis aute irure dolor in reprehenderit in voluptate velit esse</option>
</select>
使用Javascript:
jQuery(function() {
jQuery('#long').select2({
templateSelection: function (selection) {
return jQuery(selection.element).data('custom');
}
});
});