使用jquery
获取锚点的值 <div class="dataTables_paginate paging_simple_numbers" id="myTable_reports_view_paginate">
<a class="paginate_button previous disabled" aria-controls="myTable_reports_view" data-dt-idx="0" tabindex="0" id="myTable_reports_view_previous"><<</a>
<span>
<a class="paginate_button current" aria-controls="myTable_reports_view" data-dt-idx="1" tabindex="0">1</a>
<a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="2" tabindex="0">2</a>
<a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="3" tabindex="0">3</a>
<a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="4" tabindex="0">4</a>
<a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="5" tabindex="0">5</a>
<span class="ellipsis">…</span>
<a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="6" tabindex="0">33</a>
</span>
<a class="paginate_button next" aria-controls="myTable_reports_view" data-dt-idx="7" tabindex="0" id="myTable_reports_view_next">>></a>
</div>
我的问题是如何使用jquery获取值33。
提前完成。
答案 0 :(得分:4)
$('.paginate_button').last().text()
看起来你已经更新了问题,这使得答案不正确,所以下面是我更新的答案。
$('#myTable_reports_view_paginate span > a.paginate_button').last().text()
答案 1 :(得分:2)
alert($('a.paginate_button:not(.next):last').text())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="dataTables_paginate paging_simple_numbers" id="myTable_reports_view_paginate">
<a class="paginate_button previous disabled" aria-controls="myTable_reports_view" data-dt-idx="0" tabindex="0" id="myTable_reports_view_previous"><<</a>
<span>
<a class="paginate_button current" aria-controls="myTable_reports_view" data-dt-idx="1" tabindex="0">1</a>
<a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="2" tabindex="0">2</a>
<a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="3" tabindex="0">3</a>
<a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="4" tabindex="0">4</a>
<a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="5" tabindex="0">5</a>
<span class="ellipsis">…</span>
<a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="6" tabindex="0">33</a>
</span>
<a class="paginate_button next" aria-controls="myTable_reports_view" data-dt-idx="7" tabindex="0" id="myTable_reports_view_next">>></a>
</div>
您还可以使用last()
和not()
alert($('a.paginate_button').not('.next').last().text())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="dataTables_paginate paging_simple_numbers" id="myTable_reports_view_paginate">
<a class="paginate_button previous disabled" aria-controls="myTable_reports_view" data-dt-idx="0" tabindex="0" id="myTable_reports_view_previous"><<</a>
<span>
<a class="paginate_button current" aria-controls="myTable_reports_view" data-dt-idx="1" tabindex="0">1</a>
<a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="2" tabindex="0">2</a>
<a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="3" tabindex="0">3</a>
<a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="4" tabindex="0">4</a>
<a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="5" tabindex="0">5</a>
<span class="ellipsis">…</span>
<a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="6" tabindex="0">33</a>
</span>
<a class="paginate_button next" aria-controls="myTable_reports_view" data-dt-idx="7" tabindex="0" id="myTable_reports_view_next">>></a>
</div>
答案 2 :(得分:1)
Try this
$('.paginate_button:contains("33")').text()