开发者

how do i find the length of options in a combo box

How can i know is there any options in a combobox/selectbox or not?

small Edit:

i have my comboxbox as myCombo = $("#country");

now i want to know how many options are there i开发者_如何学Pythonn myCombo


In jQuery:

if($('select#something option').length > 0) {
    // There are some.
    ...


$(myCombo).children("option").length


<select id="mySelect">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
</select>

Then:

alert($('#mySelect > option').size()); //4


You can use the length property like this:

alert($('#dropdown_id option').length);

Make sure to wrap your code in ready handler:

$(function(){
  alert($('#dropdown_id option').length);
});

You can also use the size() method:

$(function(){
  alert($('#dropdown_id option').size());
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜