ms_dos

  博客园  :: 首页  :: 新随笔  ::  :: 订阅 订阅  :: 管理
js:
<script language="javascript" type="text/javascript">
        function validateChklst(source, args) { 
//验证CheckBoxList必须选择且只能选择一个
            var obj = document.getElementById('<%=chklstConclusion.ClientID%>');
            var i, k 
= 0, isCheck = false;
            var tags 
= obj.all.tags('input');
            var n 
= tags.length; //返回obj对象里具有“input”标签对象的集合
            for (i = 0; i < n; i++) {
                
if (tags[i].checked) {
                    isCheck 
= true;
                    k
++;
                }
            }
            
if (isCheck && k == 1)
                args.IsValid 
= true;
            
else
                args.IsValid 
= false;
        }
</script>
 
前台aspx
<table border="0" cellspacing="0" cellpadding="0">
                
<tr>
                    
<td width="65">
                        评价结论:
                    
</td>
                    
<td>
                        
<asp:CheckBoxList ID="chklstConclusion" runat="server" RepeatDirection="Horizontal">
                            
<asp:ListItem>允许运行</asp:ListItem>
                            
<asp:ListItem>监督运行</asp:ListItem>
                            
<asp:ListItem>暂停运行</asp:ListItem>
                            
<asp:ListItem>停止运行</asp:ListItem>
                        
</asp:CheckBoxList>
                    
</td>
                    
<td>
                        
<asp:CustomValidator ID="cvConclusion" runat="server" ErrorMessage="*请选择评价结论(只能选择一个)!"
                            ClientValidationFunction
="validateChklst"></asp:CustomValidator>
                    
</td>
                
</tr>
</table>
 
 
posted on 2011-04-29 16:36  ms_dos  阅读(894)  评论(0编辑  收藏  举报