1

你如何获得动态创建的 Asp.Net Radiobuttonlist 的计数?

这是我的单选按钮列表

<asp:RadioButtonList ID="rbl_poll" runat="server"></asp:RadioButtonList>

我试过这个但没有用

if ($("#<%=rbl_poll.clientId %>").length == 0) {
   $("#div_poll_box").hide();
}
4

3 回答 3

0

$("#rbl_poll").length should always be 1 since there should only be one element with the unique id rbl_poll.

You need to instead select the descendent elements inside the id="rbl_poll" element, for example with

if ($('#rbl_poll input[type="radio"]') === 0) {
    $('#div_poll_box').hide();
}
于 2013-04-22T09:25:55.153 回答
0

尝试选择列表中的单选按钮项目:

if ($("#rbl_poll input:radio").length == 0) {
   $("#div_poll_box").hide();
}
于 2013-04-22T09:23:55.403 回答
0

id 属性为 HTML 元素指定一个唯一的 id(该值在 HTML 文档中必须是唯一的)。

您可以使用 id(ID="rbl_poll") 的 class(class="rbl_poll") 插入

<asp:RadioButtonList class="rbl_poll" runat="server"></asp:RadioButtonList>

并更改脚本

if ($(".rbl_poll").length == 0) {
   $("#div_poll_box").hide();
}
于 2013-04-22T09:24:01.367 回答