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

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

问题描述

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

如何使用jQuery获取所选选项的索引?
可能是 .index(主题),但所有测试的可能性都不起作用......

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

PS索引:value =123=> 0,value =44=> 1,...

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

Thanx

推荐答案

这样做:

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

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

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