2

我有以下 ASP.NET RadioButtonList:

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

我想通过这样的客户端jquery函数以编程方式选择列表中的一个项目(简化版):

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

理想情况下,有一些函数 - 在上面的代码中我提出了 selectItemByValue - 通过给定值选择 RadioButtonList 中的项目。jquery 是否内置了类似的功能?如果没有,我应该如何实现所需的功能?

4

3 回答 3

5

尝试这个。

$('#<%=rbl.ClientID %>').find("input[value=" + widget.Type + "]").attr("checked", "checked");
于 2010-03-19T00:14:52.740 回答
4

选择它使用:

$("#<%=rbl.ClientID%> input[value=" + widget.Type + "]")
于 2010-03-18T23:01:36.390 回答
1
 function bindWidget(widget) {
   $('#<%-rbl.ClientId%> input:radio')
     .filter(function(btn) { return btn.value == widget.Type; })
     .attr('checked', true);
 }
于 2010-03-18T23:01:33.943 回答