开发者

how to access generated groupname for asp radiobutton

I need to access radiobutton groupname in my jquery. However, groupname that's rendered for an asp radiobutton is kind of different. Example:

<asp:RadioButton runat="server" GroupName="payment" ID="creditcard" Checked="true" value="creditcard" />

will generate:

<input type="radio" checked="checked" value="creditcard" name="ctl00$ContentPlaceHo开发者_运维知识库lder1$payment" id="ctl00_ContentPlaceHolder1_creditcard">

I can't work with <%=creditcard.GroupName%> in jquery. Is there a way I can get the generated groupname or name for it?


You can do this:

$("input[name$=payment]")

This uses the $= ends with selector, finding names that end with payment, as long as you don't have multiple of these across containers, it'll work.

Alternatively, to be based on this specific control:

$("input[name=<%=creditccard.GroupName %>]")


This will get you the proper group name

$("#<%=creditccard.ClientID %>").attr("name");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜