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

jquery通过客户端函数在radiobuttonlist中选择项

  •  2
  • mcliedtk  · 技术社区  · 16 年前

    我有以下ASP.NET RadioButtonList:

    <asp:RadioButtonList ID="rbl" runat="server">
        <asp:ListItem Text="Type1" Value="1" />
        <asp:ListItem Text="Type2" Value="2" />
    </asp:RadioButtonList>
    

    function BindWidget(widget) {
        // Type property of Widget is an int.
        $("#<%=rbl.ClientID%>").selectItemByValue(widget.Type);
    }
    

    3 回复  |  直到 16 年前
        1
  •  4
  •   Max Shawabkeh    16 年前

    选择它使用:

    $("#<%=rbl.ClientID%> input[value=" + widget.Type + "]")
    
        2
  •  5
  •   SoftwareGeek    16 年前

    $('#<%=rbl.ClientID %>').find("input[value=" + widget.Type + "]").attr("checked", "checked");
    
        3
  •  1
  •   Pointy    16 年前
     function bindWidget(widget) {
       $('#<%-rbl.ClientId%> input:radio')
         .filter(function(btn) { return btn.value == widget.Type; })
         .attr('checked', true);
     }
    
    推荐文章