通过jquery循环UI和Li

时间:2017-01-17 06:25:45

标签: javascript jquery html

我需要在jquery中循环遍历UI和li并且需要在jquery中获取标签值。我正在做一个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>
&#13;
&#13;
&#13;

我需要通过jquery获取标签值

我尝试了以下代码,但它没有循环

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

3 个答案:

答案 0 :(得分:1)

$('<%=cblUsers.ClientID %>'

似乎是未经处理的服务器端。您想使用CSS选择器,例如:

$('#ctl00_DashboardContent_cblUsers')

答案 1 :(得分:0)

您需要添加正确的查询选择器,以便按ID获取元素。试试这个:

注意#

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

答案 2 :(得分:0)

试试这个。

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