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