如何一次用两个结果进行两个验证

how to make two validation at a time with two result

本文关键字:两个 验证 何一次 结果      更新时间:2023-09-26

我创建了一个带有两个复选框的验证。

在javascript

下两个验证都可以正常工作

让我给你看看我的代码

javascipt

function Validation_agree(){
    if(document.form1.agreed1.checked==false)
    {
        $(".agreement_main").show();
        return false
    }else{
        $(".agreement_main").hide();
    }
    if(document.form1.agreed2.checked==false)
    {
        $(".agreement_terms").show();
        return false
    }else{
        $(".agreement_terms").hide();
    }
}

的形式类似于

 <div class="checkme">
  <label><input type="checkbox" value="" name="agreed1" />I have discussed all of the order details above and the customer is happy to proceed</label>
<br />
  <div class="alert agreement_main" style="display:none;">Please confirm you have informed the customer of the T&amp;Cs</div>
</div>
 <div class="redNote">
 <label><input type="checkbox" value="" name="agreed2" />I have informed the customer where they can find the T&C’s on the BT.com website</label></p>
 <div class="alert agreement_terms" style="display:none;">Please confirm you have informed the customer of the T&amp;Cs</div>
 </div>

 <input type="submit" value="submit order" /></div>
</form>                    

问题是……其中一个在更新另一个后工作
当按下提交按钮时,显示第一个验证错误消息。我想一次进行两个验证检查

谁来帮帮我提前感谢

下面的代码可能适合你。

function Validation_agree(){       
 var isValid = true;
 if(document.form1.agreed1.checked==false)       
  {           
      $(".agreement_main").show();           
         isValid = false;
   }else
    {           
      $(".agreement_main").hide();       
    }          
   if(document.form1.agreed2.checked==false)       
    {           
      $(".agreement_terms").show();           
       isValid = false;      
     }else{           
       $(".agreement_terms").hide();       
      }   
      return isValid;
}