代码之家  ›  专栏  ›  技术社区  ›  Victor

jquery checkboxlist特定元素

  •  2
  • Victor  · 技术社区  · 14 年前

    在ASP.NET复选框列表中,是否有任何方法可以确定使用jquery选中的特定复选框?例如,我需要知道是否按值或标签文本检查“全部”。

          <asp:CheckBoxList ID ="ToyotaModels" runat="server">    
                   <asp:ListItem Value = "0">Corolla<asp:ListItem>
                   <asp:ListItem Value = "1">Matrix<asp:ListItem>
                   <asp:ListItem Value = "2">Tundra</asp:ListItem>
                   <asp:ListItem Value = "3">Prius</asp:ListItem>
                   <asp:ListItem Value = "4">All</asp:ListItem>
          </asp:CheckBoxList>
    
    3 回复  |  直到 14 年前
        1
  •  1
  •   Mark Schultheiss    14 年前

    单击时将获得选中的复选框:

    $('input:checked').click().each(function() {
                //process the checkbox stuff here..
     });
    

    编辑:基于注释

     function processChecks()
    {   
        $('input:checked').each(function() 
        {
         alert($(this).val();
        });
    };
    
        2
  •  1
  •   Keltex    14 年前

    您必须查看由ASP.NET的复选框列表生成的HTML。在javascript中,作为复选框的输入容器的ID将如下所示:

    <%= ToyotaModels.ClientID %>
    

    每个复选框输入都有 _X 附加到ID,其中x是数字复选框。因此,要确定是否检查了第一个项(cololla),可以执行以下操作:

    $('<%= "#" +  ToyotaModels.ClientID + "_0" %>').is(":checked")
    
        3
  •  0
  •   Luka    14 年前

    在jquery中,您有.is(“:checked”)函数可以实现这个技巧。