【发布时间】:2014-04-20 07:29:52
【问题描述】:
Get custom data-attribute in select2 with <select>
我们需要上面链接中指定的相同内容。但是,如何在formatResult函数中获取option元素的属性呢?
【问题讨论】:
标签: html jquery-select2
Get custom data-attribute in select2 with <select>
我们需要上面链接中指定的相同内容。但是,如何在formatResult函数中获取option元素的属性呢?
【问题讨论】:
标签: html jquery-select2
你可以试试下面的代码:
$select2.data('placeholder', 'please choose').html(_options).select2({
formatNoMatches: function (term) {
return 'There is no "' + term + '" item';
},
formatResult: function(term) {
return $(term.element).data('cnt');
},
allowClear: true
});
【讨论】: