[英]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 options tag when I get the select box with $this.我有一个问题,当我得到带有 $this 的 select 框时,如何计算选项标签的数量。
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
. Select
<option>
元素,然后得到length
。
var numOptions = $this.children().length;
Learn to dig through the jQuery API docs .学习挖掘jQuery API 文档。 They will answer 99% of your questions.
他们将回答您 99% 的问题。
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...如果您想遍历 select 列表项的集合,检查 DOM 将显示每个项目都有一个 object 数组和一个项目,因此您可以使用以下代码...
$('.myddlclass').each(function (index) {
var options = $(this)[0].options.length;
});
If I understand what you're trying to do, I believe you can use如果我了解您要做什么,我相信您可以使用
$("select[name="rabetas"] option").size();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.