如何使用selectize.js計算下拉選項中的選項數量?計算selectize.js中選項的數量
$('#MyDrop option').length;
$('#MyDrop option').size();
以上的人不與selectize工作!
如何使用selectize.js計算下拉選項中的選項數量?計算selectize.js中選項的數量
$('#MyDrop option').length;
$('#MyDrop option').size();
以上的人不與selectize工作!
使用Selecize API,你可以用這個方法選擇:
options = $('#my_select_widget')[0].selectize.options;
然後遍歷對象指望他們:
var cnt = 0;
for(k in options){
cnt++;
}
console.log(cnt);
獲取selectize的所有選項
let options = $('#selectElem')[0].selectize.options;
獲取對象的所有密鑰
let count = Object.keys(options);
console.log(count.length);
謝謝ahmed。它解決了我的問題:D –