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());
});
精彩评论