[英]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.