验证在4之间至少选中一个复选框 [英] Validate that at least one check box is checked between 4
本文介绍了验证在4之间至少选中一个复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在网页上有4个复选框,我希望客户端验证在提交表单之前至少应该检查一个复选框。
所以,我已经编写了以下代码来验证单个复选框。
< asp:CheckBox ID = CheckBoxTermsandCondition runat = 服务器字体名称= Calibri字体大小= 小 ForeColor = Black />我同意条款和条件
< asp:CustomValidator ID = CustomValidator1 runat = server ErrorMessage = 您必须同意我们的条款和条件 ClientValidationFunction = ValidateCheckBox > < / asp:CustomValidator > < br /> < / div >
< script type = text / javascript>
function ValidateCheckBox(sender,args){
if ( document .getElementById( <%= CheckBoxTermsandCondition.ClientID%> )。checked == true ){
args.IsValid = true ;
} else {
args.IsValid = false ;
}
}
< / script>
解决方案
参考: JavaScript的验证码到化妆确保-该-AT-至少酮复选框-被标记 [ ^ ]
试试这个jquery:
var checked = 0 ;
(< span class =code-string> input [type = checkbox])。live( 点击, function (){
如果跨度>(
I have 4 check boxes on the web page, i want client side validation that ate least one check box should be check before submitting the form.
So, Far i have write the following code to validate a single check box.
<asp:CheckBox ID="CheckBoxTermsandCondition" runat="server" Font-Names="Calibri" Font-Size="Small" ForeColor="Black" /> I Agree with Terms and Condition
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="You Must Agree Upon our terms and condition" ClientValidationFunction = "ValidateCheckBox"></asp:CustomValidator><br /></div>
<script type = "text/javascript">
function ValidateCheckBox(sender, args) {
if (document.getElementById("<%=CheckBoxTermsandCondition.ClientID %>").checked == true) {
args.IsValid = true;
} else {
args.IsValid = false;
}
}
</script>
解决方案
Refer: javascript-validation-code-to-make-sure-that-at-least-one-checkbox-is-marked[^]
Try this jquery :
var checked = 0;
("input[type=checkbox]").live("click", function() { if(
这篇关于验证在4之间至少选中一个复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文