我保持一些舊的C#代碼,並有一個asp:單選按鈕列表...獲取屬性:單選按鈕列表使用jQuery
<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')
...但都沒有工作。任何人都可以提出一種獲得該屬性值的方法嗎?
你嘗試用ID結尾的方法:'$( 「[ID $ = '_ radIncidentType']」)'和類似的理由? –
謝謝,是的,嘗試過這一點,它現在正在工作 – atamata