gpt4 book ai didi

jquery:如何获取下拉选项序列号?

转载 作者:行者123 更新时间:2023-12-01 02:23:32 25 4
gpt4 key购买 nike

示例:

<select id="myselect">
<option value="A">First</option>
<option value="B">Second</option>
<option value="C" selected="selected">Third</option>
<option value="D">Fourth</option>
</select>

使用jquery,我想获取选定的选项序列号,即“3”

谢谢

最佳答案

<script type="text/javascript">
jQuery(document).ready(function(){
var val =$('#myselect option:selected').val();
alert(val) // alerts C
var txt =$('#myselect option:selected').text();
alert(txt) // alerts Third
var seqNo=$('#myselect option:selected').index()+1; // +1 because first element counted as zero
alert(seqNo); // gives the required sequence number
});
</script>

关于jquery:如何获取下拉选项序列号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8820017/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com