gpt4 book ai didi

jquery - 保持检测单选按钮中选定的值

转载 作者:行者123 更新时间:2023-12-01 04:49:59 24 4
gpt4 key购买 nike

下面的代码在加载时会引发警报,因为它检测到第二个单选按钮已被选中。但是如果我选择第一个,然后再次选择第二个,则不会引发警报..为什么?

http://jsfiddle.net/h6j58/3/

<input type="radio" id="s530351a84b2aa_tipo_0" name="radioName" required="required" value="0"  >
<input type="radio" id="s530351a84b2aa_tipo_1" name="radioName" required="required" value="1" checked="checked">

$(document).ready(function(){
if($("input[name=radioName]:checked").val() == 1)
{
alert("fajslf");
}
});

最佳答案

发生这种情况是因为您没有捕获任何事件,只是检查文档加载上是否检查了您的特定radion。您需要捕获单选按钮的 change 事件,如以下代码所示:

$("input[name=radioName]").on("change", function () {
if($("input[name=radioName]:checked").val() == 1)
{
alert("fajslf");
}
});

Fiddle demo

关于jquery - 保持检测单选按钮中选定的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21854696/

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