gpt4 book ai didi

jQuery 验证和分组 - 当第二个字段值正确时无法正常工作?

转载 作者:行者123 更新时间:2023-12-01 05:01:22 25 4
gpt4 key购买 nike

我有一些字段,它们属于组 - demo 的一部分。当用户在第一个字段中输入错误的数据(在我的演示中为数字(1 到 10))时,会显示错误消息。但是,当用户在第二个字段中输入正确的数据(数字(11 到 20))时,如果组中的一个字段仍然包含不正确的数据,则此消息消失。此外,错误类被删除(这在演示中不可见)。

我该如何纠正这个问题?

最佳答案

众所周知,这个问题与 jQuery 验证组有关。

我的解决方案非常简单。

首先,您需要将相同的类添加到组中的所有输入:

<input id="firstInGroup" class="groupBug">
<input id="secondInGroup" class="groupBug">
<input id="thirdInGroup" class="groupBug">

然后,您为该类创建一个触发器

    $('.groupBug').change(function(){
if($(this).siblings().valid()){
//all items of the group are valid, do nothing or manually add valid class
}else{
//add the error class to the parent div, or whatever you want for the error
}

它对我来说有几个选择。

关于jQuery 验证和分组 - 当第二个字段值正确时无法正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9691250/

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