【发布时间】:2017-09-04 19:06:30
【问题描述】:
我正在维护一些旧的 c# 代码,并且有一个 asp:RadioButtonList...
<asp:RadioButtonList AutoPostBack="false" TextAlign="Right" RepeatDirection="Horizontal" RepeatLayout="Flow" runat="server" ID="radIncidentType" />
... 在后面的代码中填充如下:
public static void PopulateRBL(string ListName, ref RadioButtonList ListToPopulate)
{
List<Lookup> radioList = GetLookup(ListName); //returns
foreach (Lookup entry in radioList)
{
ListItem item = new ListItem(" " + entry.Description + " ", entry.Code);
item.Attributes.Add("ItemId", entry.Id.ToString());
ListToPopulate.Items.Add(item);
}
}
所以添加的每个项目都有一个描述、一个代码和一个额外的属性ItemId。
然后在 onChange 上执行一些验证,它必须询问 ItemId 属性。目前是这样的:
$('#ctl00_cphPage_radIncidentType input[type=radio]:checked').closest('span').attr('ItemId')
在我添加嵌套母版页之前,它工作正常,为了让它工作,我不得不将选择器更改为:
$('#ctl00_ctl00_cphPage_nestedPage_radIncidentType input[type=radio]:checked').closest('span').attr('ItemId')
显然我想要一个更整洁的选择器,我试过了:
$('#<%= radIncidentType.ClientID %> input[type=radio]:checked').closest('span').attr('ItemId')
和...
$("input[name='<%=radIncidentType.UniqueID%>']:radio:checked").closest('span').attr('ItemId')
...但两者都不起作用。任何人都可以提出一种获取 ItemId 属性值的方法吗?
【问题讨论】:
-
您是否尝试过 ID 以方法结尾:
$("[id$='_radIncidentType']")和类似的理由? -
谢谢,是的,试过了,现在可以用了
标签: javascript c# jquery asp.net radiobuttonlist