开发者

how can I calculate number of options tag when I get the select box with $this

I have a question as to how can I calculate number of op开发者_开发问答tions tag when I get the select box with $this.

Like that:

 $("select[name=rabetas]").click(function(){
   var $this = $(this);

And...?

how can I do this?


Select the <option> elements, and then get the length.

var numOptions = $this.children().length;

Learn to dig through the jQuery API docs. They will answer 99% of your questions.


Counting the number of options tag in the Select Dom element in JQuery


If I understand what you're trying to do, I believe you can use

$("select[name="rabetas"] option").size();


If you want to loop through a collection of select list items, inspecting the DOM will show that each item has an object array with one item so you can use the following code...

$('.myddlclass').each(function (index) {
    var options = $(this)[0].options.length;
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜