简体   繁体   English

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

[英]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.

相关问题 如何知道选择框中的可用选项何时更改 - How can I know when the available options in a select box changes 当我 select 输入框时,如何将“您正在输入数字”放在输入框的正下方? - How can i put "you are entering a number" right below the input box when i select input box? 如何根据选择框中选择的不同选项来显示不同的图片? - How can I get different pictures being shown depending on the different options being selected in a select box? 如何使用 JSON 数据填充选择框的选项? - How can I use JSON data to populate the options of a select box? 如何在 safari 中以编程方式隐藏打开的选择框中的选项? - How can I hide the options in an open select box programmatically in safari? 从窗口中的任何位置单击选择框时,如何获得选择框关闭事件? - How can i get Select box close event when click out of the select box any where in window? 当我跳入选择框时,如何在选择框中显示选项? - how do i show the options in a select box when i tab into the box? 我怎样才能 select 多选 select 点击框的所有选项? - How can I select all options of multi-select select box on click? 当我单击“计算”按钮时,它如何获取每个A,B框中的值,并将这些值传递给服务器以计算结果并发出Alert()? - When I click the “Calculate” button, how can it get the values in each box A,B and pass those value to server to calculate and alert() the result? 如何在反应 js 中获得多个 select 选项? - How can i get multiple select options in react js.?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM