日期:2014-05-18  浏览次数:20403 次

关于checkBoxList1 验证问题
由于我的数据绑定   是动态的
    <asp:CheckBoxList   ID= "CheckBoxList1 "   name= "checklistMessage "   runat= "server "   DataTextField= "InsTypeName "     DataValueField= "InsTypeId "   RepeatDirection= "Horizontal "   RepeatLayout= "Flow "   Width= "600px ">
  </asp:CheckBoxList>
所以网上那个js   验证无法使用$( ":checkbox[name= 'xqah_more '] ").formValidator({tipID: "test2Tip ",onShow: "请选择险种(至少选择1个,最多选择4个) ",onFocus: "你至少选择1个,最多选择4个 ",onCorrect: "恭喜你,你选对了 ",defaultValue:[ "7 ", "8 "]}).inputValidator({min:1,max:4,onError: "你选的个数不对(至少选择1个,最多选择4个) "});
现在请问各位大侠,我要如何验证呢?

------解决方案--------------------
遍历一下,看看cheched的数量
------解决方案--------------------
var count=0;
var container=document.getElementById("<%= CheckBoxList1.ClientID%>");
var cbList=container.getElementsByTagName("input");
for(var i=0;i<cbList.length;i++){
if(cbList[i].type=="checkbox"&&cbList[i].checked){
count++;
}
}

------解决方案--------------------
参考相关:
http://www.cnblogs.com/insus/archive/2011/06/17/2081639.html
内有方法保存选择结果,你可以无需保存,保对选择的结进行判断,是不为1与4个之间。