bootstrap select selectpicker動態賦值與賦默認值、多選


<select name="e_id" id="e_id" class="selectpicker" data-live-search="true" multiple >
<option disabled>請選擇</option>
<option value="">文字</option>
</select>

 

動態賦值

 var str = ''; for (var i = 0; i < response.data.id_with_codes.length; i++){ str += '<option value="'+ response.data.id_with_codes[i][0] +'">'+ response.data.id_with_codes[i][1] +'</option>' } // 將動態拼接的數據渲染 $('#waterfall-is-rules').html(str); // 刷新 $('#waterfall-is-rules').selectpicker('refresh'); 

賦默認值

  $('#waterfall-is-rules').selectpicker('val', response.data.cash.entry_type);


獲取多選值
var checkParam = $('#e_id').find('option:selected');
// 選中的ID集合
var checkId = [];
for (var i=0;i<checkParam.length;i++) {
checkId.push(checkParam[i].value);
}
var e_id = checkId.join(',');
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM