1.处理
$('#spec1_cont').select2({ placeholder: "请选择", allowClear: true});
2.获取选择的id
var spec1_cont_val = $('#spec1_cont').select2("val");
3.获取选择的内容和id
var spec1_cont_val = [];$("#spec1_cont option:checked").each(function(i){ spec1_cont_val[i] = $(this).val()+'-'+$(this).text(); // 1-红色 3-绿色})var spec2_cont_val = [];$("#spec2_cont option:checked").each(function(i){ spec2_cont_val[i] = $(this).val()+'-'+$(this).text();})
4.默认选择
if (default_val_arr) { // ['1','3'] $("#spec1_cont").val(default_val_arr).trigger('change');//设置select的默认值}