[英]Getting name of not checked radio button
I want to get the value of the not checked radio button. 我想获取未选中单选按钮的值。
This is my code: 这是我的代码:
<input type="radio" name="myradios" value="rad1" checked="checked" />
<input type="radio" name="myradios" value="rad2" />
<script>
var notchecked = $('input:radio[name=myradios]:not(checked)');
console.log(notchecked.val())
</script>
But it gives me rad1
, instead of rad2
. 但这给了我
rad1
而不是rad2
。
Here is a fiddle: https://jsfiddle.net/fsj1hm2g/ 这是一个小提琴: https : //jsfiddle.net/fsj1hm2g/
You need to correctly use the :checked
selector: 您需要正确使用
:checked
选择器:
$('input:radio[name=myradios]:not(:checked)');
See Documetation 见文档
Use var notchecked = $('input:radio[name=myradios]:not(:checked)');
使用
var notchecked = $('input:radio[name=myradios]:not(:checked)');
instead of :not(checked)
代替
:not(checked)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.