select2的使用

下载地址:
https://github.com/select2/select2/tags



文档地址:
https://select2.org/


引用:




初始化:
$("#startAirCode").select2();


var data = https://www.it610.com/article/[
{
id: 0,
text: 'enhancement'
},
{
id: 1,
text: 'bug'
},
{
id: 2,
text: 'duplicate'
},
{
id: 3,
text: 'invalid'
},
{
id: 4,
text: 'wontfix'
}
];
$("#startAirCode").select2({
data: data,
placeholder: '请选择'
});



清空:
$("#startAirCode").empty();
// 官网文档中的方法
$('#startAirCode').val(null).trigger('change');


获取选中的值:
//取text
var strtext = $('#startAirCode').select2('data').text;
//取value
var str2value= https://www.it610.com/article/$("#startAirCode").select2("val");


赋值:
$('#startAirCode').val(['1']).trigger('change');
【select2的使用】

    推荐阅读