簡體   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