checkboxlist 选择为空时的判断(customvalidator[用户自定义验证控件]的应用):

来源:互联网 发布:手机淘宝怎么查积分 编辑:程序博客网 时间:2024/05/19 01:13
checkboxlist 选择为空时的判断(customvalidator[用户自定义验证控件]的应用):
  <script language="javascript" type="text/javascript">
  function check(source,args)
  {
  var obj=document.getElementById('<%=this.huanjing.ID%>');//返回具有和属性id的值相同或相似的对象集合
  var k,bol=false;
  var ln=(obj.all.tags('input').length);//返回obj对象里具有“input”标签对象的集合
  for(k=0;k<ln;k++)
  {
  //alert(" name:"+obj.all.tags('input')[k].name+"是否:"+obj.all.tags('input')[k].checked);
  
  if(obj.all.tags('input')[k].checked) // obj对象里具有input标签对象键值为k的属性为checked的值
  bol=bol||true;
  }
  if(bol)
  args.IsValid=true;
  else
  args.IsValid=false;
  
  }
  
  </script>

<asp:checkboxlist id="huanjing" runat="server" Height="36px" Width="400px" RepeatDirection="Horizontal">
<asp:ListItem Value="Win98">Win98</asp:ListItem>
<asp:ListItem Value="WinMe">WinMe</asp:ListItem>
<asp:ListItem Value="WinXP">WinXP</asp:ListItem>
<asp:ListItem Value="Win2000">Win2000</asp:ListItem>
<asp:ListItem Value="Win2003">Win2003</asp:ListItem>
<asp:ListItem Value="Unit">Unit</asp:ListItem>
</asp:checkboxlist><asp:customvalidator id="CustomValidator1" runat="server" 
ErrorMessage="运行环境没有选择,请选择运行环境" ClientValidationFunction="check"></asp:customvalidator>