最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Count number of options in selectize.js - Stack Overflow

programmeradmin1浏览0评论

how to count number of options in dropdown using selectize.js?

$('#MyDrop option').length;

$('#MyDrop option').size();

Above ones are not working with selectize !

how to count number of options in dropdown using selectize.js?

$('#MyDrop option').length;

$('#MyDrop option').size();

Above ones are not working with selectize !

Share Improve this question edited Nov 9, 2015 at 19:26 pnuts 59.5k11 gold badges91 silver badges141 bronze badges asked Sep 4, 2015 at 6:31 Abubakar IkramAbubakar Ikram 4531 gold badge9 silver badges24 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 8

Get all options of selectize

let options = $('#selectElem')[0].selectize.options;

Get all keys of object

let count = Object.keys(options);
console.log(count.length);

Using the Selecize API, you can get options with this method:

options = $('#my_select_widget')[0].selectize.options;

Then loop through the object to count them:

var cnt = 0;
for(k in options){
    cnt++;
}
console.log(cnt);
发布评论

评论列表(0)

  1. 暂无评论