簡體   English   中英

通過 jquery 循環 Ul 和 Li

[英]Looping Ul and Li through jquery

我需要在 jquery 中遍歷 Ul 和 li 並需要在 jquery.I 中獲取標簽值。我正在做一個 asp.net c#

我的 Html 如下

 <ul id="ctl00_DashboardContent_cblUsers" class="reprp checkWrp scroll" style="width: 100%;"> <li> <span title="Thomas"><input name="ctl00$DashboardContent$cblUsers$1" /> <label for="ctl00_DashboardContent_cblUsers_0">Thomas</label> </span> </li> <li> <span title="Abraham"><input name="ctl00$DashboardContent$cblUsers$1" /> <label for="ctl00_DashboardContent_cblUsers_1">Abraham</label> </span> </li> </ul>

我需要通過 jquery 獲取標簽值

我已經嘗試了以下代碼,但它沒有循環

$('<%=cblUsers.ClientID %>').find('li').each(function (index, element) {
});
$('<%=cblUsers.ClientID %>'

似乎是未處理的服務器端。 您想使用 CSS 選擇器,例如:

$('#ctl00_DashboardContent_cblUsers')

您需要添加適當的查詢選擇器以通過 Id 獲取元素。 嘗試這個:

注意#

 $('#' + '<%=cblUsers.ClientID %>').find('li').each(function (index, element) { });

嘗試這個。

<script type="text/javascript">
    $('.reprp').find('li').each(function (index, element) {
        var text = $(this).find('label').text();
        console.log( text );
    });
</script>

暫無
暫無

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

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