gpt4 book ai didi

javascript - 如何一次进行两个验证并得到两个结果

转载 作者:行者123 更新时间:2023-11-30 13:25:48 25 4
gpt4 key购买 nike

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

两种验证都可以使用 javascript 正常工作

让我给你看我的代码

javascript

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;
}

关于javascript - 如何一次进行两个验证并得到两个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8537569/

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