请教!用JS检测UpdatePanel 中的DataList 中的 CheckBoxList 是否有被选中,无选中则弹出提示框
页面代码如下:<div style="height: 100%">
<asp:HiddenField ID="hfUserid" runat="server" />
<asp:HiddenField ID="hfMesid" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DataList ID="dlt" runat="server" DataKeyField="autoid" OnItemDataBound="dlt_ItemDataBound"
RepeatDirection="Vertical">
<ItemTemplate>
<asp:CheckBox ID="cb" runat="server" OnCheckedChanged="cb_CheckedChanged" AutoPostBack="true" /><%#Eval("MenuName") %>
<asp:CheckBoxList ID="cbl" AutoPostBack="true" runat="server" RepeatDirection="Horizontal"
RepeatColumns="6">
</asp:CheckBoxList>
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
页面代码如下:<div style="height: 100%">
<asp:HiddenField ID="hfUserid" runat="server" />
<asp:HiddenField ID="hfMesid" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DataList ID="dlt" runat="server" DataKeyField="autoid" OnItemDataBound="dlt_ItemDataBound"
RepeatDirection="Vertical">
<ItemTemplate>
<asp:CheckBox ID="cb" runat="server" OnCheckedChanged="cb_CheckedChanged" AutoPostBack="true" /><%#Eval("MenuName") %>
<asp:CheckBoxList ID="cbl" AutoPostBack="true" runat="server" RepeatDirection="Horizontal"
RepeatColumns="6">
</asp:CheckBoxList>
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
var flag=true;for(var i=0,len=els.length;i<len;i++)
{
if(els[i].type=='checkbox'&&els[i].checked)
{
flag=false;
break;
}
}if(flag)
{
alert('必须选中一项');
}
这里,总是提示选择一项,但已经选了
<form id="form1" runat="server">
<div style="width: 500px; text-align: center; margin-left: 20%">
<table style="width: 100%; border: 0; background-color: #b5d6e6" cellpadding="0"
cellspacing="1">
<tr>
<td colspan="2" style="height: 22px; background-image: url(../images/bg.gif)">
角色信息
</td>
</tr>
<tr>
<td style="width: 7%; height: 25px; text-align: center; background-color: #FFFFFF">
角色名
</td>
<td style="text-align: center; background-color: #FFFFFF; width: 36%">
<asp:TextBox ID="txtRoleName" runat="server" onblur="this.style.background='#FFFFFF'"
onfocus="this.style.background='#e4f8f0';" Width="95%" />
<asp:HiddenField ID="hfNewid" runat="server" />
<asp:HiddenField ID="hfTypeID" runat="server" />
<asp:HiddenField ID="hfRoleID" runat="server" />
</td>
</tr>
<tr>
<td style="height: 25px; text-align: center; background-color: #FFFFFF">
权限
</td>
<td style="text-align: left; background-color: #FFFFFF;">
<asp:TreeView ID="TreeMenu" runat="server" ShowLines="True" ShowCheckBoxes="All">
</asp:TreeView>
</td>
</tr>
<tr>
<td style="height: 25px; text-align: center; background-color: #FFFFFF">
备注
</td>
<td style="text-align: center; background-color: #FFFFFF">
<asp:TextBox ID="txtRe" runat="server" onblur="this.style.background='#FFFFFF'"
onfocus="this.style.background='#e4f8f0';" Width="95%"></asp:TextBox>
</td>
</tr>
<tr>
<td style="text-align: center; background-color: #FFFFFF; height: 25" colspan="2">
<asp:Button ID="btnSubmit" runat="server" CssClass="button60F" Text="确认" OnClientClick="return DataCheck()"
OnClick="btnSubmit_Click" />
<asp:Button ID="btnBack" runat="server" CssClass="button60" Text="返回" OnClick="btnBack_Click" />
</td>
</tr>
</table>
</div>
</form>
<asp:TreeView ID="TreeMenu" runat="server" ShowLines="True" ShowCheckBoxes="All">
</asp:TreeView>
</div>然后var els = document.getElementById('<%=dlt.ClientID%>').getElementByTagName('input');=》var els = document.getElementById('div').getElementByTagName('input');