计算jQuery中选择标签中的选项标签的数量 [英] Counting the number of option tags in a select tag in jQuery

查看:435
本文介绍了计算jQuery中选择标签中的选项标签的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jQuery计算<select> DOM元素中<option>的数量?

How do I count the number of <option>s in a <select> DOM element using jQuery?

<select data-attr="dropdown" id="input1">
  <option value="Male" id="Male">Male</option>
  <option value="Female" id="Female">Female</option>
</select>

我想在<select> DOM元素中找到<option>标记的数量,因为我想用该输入字段的数量打开带有相应选项值的输入面板的设置面板,该下拉列表位于并在预览面板中再次进行更改.

I want to find the number of <option> tags in the <select> DOM element, since with that I want to open the settings panel with that number of input fields with the corresponding option value from the drop-down box in it and to change it again in the preview panel.

上面的下拉框在我的预览面板中,该面板由jQuery生成.

The above drop-down box is in my preview panel which is generated by jQuery.

推荐答案

$('#input1 option').length;

这将产生2.

这篇关于计算jQuery中选择标签中的选项标签的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆