簡體   English   中英

如何獲得正確的ClientID

[英]how to get correct ClientID

更新:asp.net

<asp:RadioButtonList runat="server" ID="rbl" RepeatDirection="Horizontal">
    <asp:ListItem Text="None" Value="0" Selected="True" Enabled="true" />
    <asp:ListItem Text="Float" Value="1" Selected="False" Enabled="true" />
    <asp:ListItem Text="Float1" Value="2" Selected="False" Enabled="true" />
    <asp:ListItem Text="Center" Value="3" Selected="False" Enabled="false" />
</asp:RadioButtonList>

當我查看源代碼時,它就是渲染的內容:

$('#ctl00_ctl00_ContentMain_rbl').hover(         
    function (){
        $('#div1').dialog({title: "some title"});
        $('#div1').dialog('open');
    }
);

正確的ctl00_ctl00_ContentMain_rbl_0, ctl00_ctl00_ContentMain_rbl_1, ctl00_ctl00_ContentMain_rbl_2是: ctl00_ctl00_ContentMain_rbl_0, ctl00_ctl00_ContentMain_rbl_1, ctl00_ctl00_ContentMain_rbl_2

代碼不起作用,當我嘗試閱讀時,它沒有給我正確的ClientID名稱。對於此問題,反過來又是什么,請定義類名稱?

   $('#<%= rbl.ClientID %>').hover(   
            function (){
                $('#div1').dialog({title: "Float Images Left"});
                $('#div1').dialog('open');
            }            );

是的,最簡單的方法是為要使用jQuery查找的所有組件定義class

另一種方法是使用以選擇器結尾屬性

$('[id$="_rbl"]').hover( // Etc.

但是,如果在另一個容器中有另一個rbl則可能會導致問題。

請記住,您在RadioButtonList中的項目將作為輸入,然后您可以執行以下操作:

$('[id$="_rbl"] input:enabled').hover( // Etc.

因此,如果您為RadioButtonList定義一個類:

$(".myclass input:enabled").hover( // Etc.

如果要對單選按鈕進行懸停操作,則必須定位輸入

$('#<%= rbl.ClientID %> input').hover(   
    function (){
        $('#div1').dialog({title: "Float Images Left"});
        $('#div1').dialog('open');
    }
);

這就是我如何達到我想要的。

為每個列表項定義類

 <asp:RadioButtonList runat="server" ID="rbl" RepeatDirection="Horizontal">
        <asp:ListItem class="rb0" Text="None" Value="0" Selected="True" Enabled="true" />
        <asp:ListItem class="rb1" Text="Float" Value="1" Selected="False" Enabled="true" />
        <asp:ListItem class="rb2" Text="Float1" Value="2" Selected="False" Enabled="true" />
        <asp:ListItem class="rb3" Text="Center" Value="3" Selected="False" Enabled="false" />
    </asp:RadioButtonList>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM