如何获取select->option标签的索引 [英] How to get the Index of select->option tag

查看:21
本文介绍了如何获取select->option标签的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<select id="sel">
<option value="123" selected="selected">text1</option>
<option value="44">text2</option>
<option value="882">text3</option>
...
</select>

如何使用 jQuery 获取所选选项的索引?可能是 .index(subject),但所有的可能性都经过测试,没有奏效...

How to get the index of selected option with jQuery? May be .index(subject), but all possibilities tested, didn't work...

附言索引:value="123" => 0, value="44" => 1, ...

P.S. Indexes: value="123" => 0, value="44" => 1, ...

谢谢

推荐答案

这样做:

   $("#sel").attr("selectedIndex")

这篇关于如何获取select->option标签的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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