jquery如何获得被选中的option索引

2024-10-12 09:29:56

1、新建一个html文件,命名为test.html,用于讲解jquery如何获得被选中的option索引。

jquery如何获得被选中的option索引

2、使用select标签创建一个下拉列表,用于测试。

jquery如何获得被选中的option索引

3、在script标签内,通过id获得select对象,使用prop()方法,通过selectedIndex属性获得被选中的option索引。最后,通过alert()方法将索引值输出。

jquery如何获得被选中的option索引

4、在浏览器打开test.html文件,查看结果。

jquery如何获得被选中的option索引
猜你喜欢