验证复选框 [英] validation of checkboxes

查看:78
本文介绍了验证复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我想验证我的页面有5个文本框和4个复选框,每个都指向文本框,

i没有选中复选框列表,现在我检查了两个文本框是保留空,并且选中至少1个复选框,如何实现此

Hello, I want to validate my page which has there are 5 text boxes and 4 checkboxes,each refer to text box,
i have not selected checkbox list, now i have check neither text box is left empty, and atleast 1 checkbox is selected, how to achieve this

推荐答案

您可以使用JavaScript分别验证每个控件,您需要获取所有文本框和复选框验证它。

见下面的代码片段

You can use JavaScript to validate each control separately, you need to get all textboxes and checkboxes to validate it.
see below snippet
<script language="Javascript">
function validate()
{
   if (!(Checkbox1.checked || Checkbox2.checked || Checkbox3.checked || Checkbox4.checked))
      {
          alert("Please check any of the checkboxes");
          return false;
      }

   if (!(Txt1.Text != "" || Txt2.Text != "" || Txt3.Text != "" || Txt4.Text != ""))
      {
          alert("Please check any of the Textboxes");
          return false;
      }
}
</script>


这篇关于验证复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆