jquery获得select选中索引

$('#someId').prop('selectedIndex');
$('option:selected', '#someId').index();
$('#someId option').index($('#someId option:selected'))
以上三种方式可以取到索引值
纠正jquery获取radio值的做法
网上流行的说法就是
$(input[name='aaa'][checked]).val()
能取到选中项的value,但测试后发现只在IE下有效,在firefox和Chrome中不论选中哪一项,或者不选,取到的值都是第一项的value
正确做法应该是
$("input[name='aaa']:checked").val()
同样对于checkbox也是这种写法

相关文章:

  • 2021-09-25
  • 2022-01-21
  • 2021-05-25
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-08
  • 2022-01-23
  • 2021-08-13
  • 2021-08-17
相关资源
相似解决方案