使用jQuery获取最后一个可见元素 [英] Get last visible element using jQuery
本文介绍了使用jQuery获取最后一个可见元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<table>
<tr class="here" id="t1" number="1" ><td>1</td></tr>
<tr class="here" id="t2" number="2" ><td>2</td></tr>
<tr class="here" id="t3" number="3" style="display:none"><td>3</td></tr>
<tr class="here" id="t4" number="4" style="display:none"><td>4</td></tr>
</table>
<span id="check">check</span>
$('#check').click(function(){
check = ???;
alert(check);
})
DEMO: http://jsfiddle.net/vUukc/1/
如何获取属性数字
从这个例子中的最后一个可见的 tr
?这是一个例子 - 所有< tr>
都可见。
How can I get the attribute number
from last visible tr
in this example? This is an example - all <tr>
could be visible.
推荐答案
出于这些目的,有不同的 jQuery选择器。
There are different jQuery Selectors for those purposes.
例如:
$('table tr:visible:last').attr('number');
或
$('table tr:visible').last().attr('number');
等等。
完整代码
$('#check').click(function() {
check = $('table tr:visible:last').attr('number');
alert(check);
});
DEMO
这篇关于使用jQuery获取最后一个可见元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文