如何使用jQuery从属性名称中获取单选按钮组的布尔值而不是实际选择的文本
答案 0 :(得分:0)
$(“ input [name ='MainColumn']”)。is(':checked')
console.log($("input[name='MainColumn']").is(':checked'));//true or false
console.log($("input:radio[name=MainColumn]:checked").length);//0 or 1
$("input").on('click',function(){
console.log($("input[name='MainColumn']").is(':checked'));//true or false
console.log($("input:radio[name=MainColumn]:checked").length)//0 or 1
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="radio" name="MainColumn" value="male"> Male<br>
<input type="radio" name="MainColumn" value="female"> Female<br>
<input type="radio" name="MainColumn" value="other"> Other