gpt4 book ai didi

javascript - Jquery 条件 && 未显示预期结果

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

我正在尝试验证一个复杂的表单。在此示例中,我检查所有单选按钮都有一个值

if ($('input[name=brand]:checked').val()!="" && $('input[name=section]:checked').val()!="" ) {
alert("both selected all is well");
$("a.gobutfton").addClass("ok");
} else{
alert("They are still not all selected");
}

即使只单击一个,我也会收到“两者都被选中”的警报(用于测试)考虑到我将有多个项目和表单类型,我什至无法让其中两个按照我想象的方式运行 http://jsfiddle.net/Lrz8vrdd/1/

最佳答案

一个或两个都是“未定义”。尝试一下

if ($('input[name=brand]:checked').val() && $('input[name=section]:checked').val())

这确保了两者都不为 0、空字符串、未定义或 null。

关于javascript - Jquery 条件 && 未显示预期结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25224729/

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