繁体   English   中英

当我得到带有 $this 的 select 框时,如何计算选项标签的数量

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

我有一个问题,当我得到带有 $this 的 select 框时,如何计算选项标签的数量。

像那样:

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

和...?

我怎样才能做到这一点?

Select <option>元素,然后得到length

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

学习挖掘jQuery API 文档 他们将回答您 99% 的问题。

如果您想遍历 select 列表项的集合,检查 DOM 将显示每个项目都有一个 object 数组和一个项目,因此您可以使用以下代码...

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

如果我了解您要做什么,我相信您可以使用

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM