gpt4 book ai didi

jquery - 如何在 jQuery 中检查每个组中的单选按钮是否被选中?

转载 作者:行者123 更新时间:2023-12-03 21:48:20 24 4
gpt4 key购买 nike

多个组或单选按钮

<h1>Question 1</h1>
<input type="radio" name="radio1" value="false" />
<input type="radio" name="radio1" value="true" />

<h1>Question 2</h1>
<input type="radio" name="radio2" value="false" />
<input type="radio" name="radio2" value="true" />

如何在 jQuery 中检查每个组中的单选按钮是否已选中?

谢谢。

最佳答案

这是我的做法:

var all_answered = true;
$("input:radio").each(function(){
var name = $(this).attr("name");
if($("input:radio[name="+name+"]:checked").length == 0)
{
all_answered = false;
}
});
alert(all_answered);

这样您就不需要依赖兄弟标签或父标签。如果您的单选按钮与任何标签混合在一起,它仍然可以工作。您可以play around with it .

关于jquery - 如何在 jQuery 中检查每个组中的单选按钮是否被选中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3553197/

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