[英]How to add Required Field Validator to checked ListBox?
我在div标签中使用了选中的列表框,我想验证选中的列表框。 我该如何实现?
您可以使用javascript来验证复选框列表。 请找到以下代码来了解一下:
<script type = "text/javascript">
var minOccurance= 1
function Validate()
{
var yourCheckboxList= document.getElementById("<%=CheckBoxList1.ClientID%>");
var checkbox = yourCheckboxList.getElementsByTagName("input");
var counter=0;
for (var i=0;i<checkbox.length;i++)
{
if (checkbox[i].checked)
counter++;
}
if(minOccurance>counter)
{
alert("Please select atleast " + minOccurance + " item(s)");
return false;
}
return true;
}
</script>
希望这能解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.