javascript 获取下一个可见且没有属性的元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14168598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get Next Element that is Visible and Does Not Have Attribute
提问by Jonathan Wood
I'm an experienced developer with not so much experience in jQuery.
我是一位经验丰富的开发人员,在 jQuery 方面没有太多经验。
I have a table row (<tr>
) element and I'd like to use jQuery to get the next table row that A)is visible, and B)does not have the attribute id='count-me-out'
.
我有一个表格行 ( <tr>
) 元素,我想使用 jQuery 来获取A)可见且B)没有属性的下一个表格行id='count-me-out'
。
I think I could do this in a loop (although I have some question about checking visibility regardless of what attributes are being used to control visibility). But what what I'd really like is to pass a selector argument to $(myTr).next()
that would implement this filter.
我想我可以在循环中做到这一点(尽管我有一些关于检查可见性的问题,而不管使用什么属性来控制可见性)。但是我真正想要的是传递一个选择器参数来$(myTr).next()
实现这个过滤器。
Is this possible?
这可能吗?
回答by Roko C. Buljan
http://jsbin.com/apaxev/1/edit
http://jsbin.com/apaxev/1/edit
var lookingFor = $(this).nextAll('tr:visible').not('#count-me-out').first();
Or like:
或者像:
var lookingFor = $(this).nextAll( 'tr:visible:not("#count-me-out"):first ');
回答by Ortiga
You probably want:
你可能想要:
$(el).next(':not(#count-me-out):visible')
Edit: This is not a valid answer. See comments.
编辑:这不是一个有效的答案。看评论。