为什么我隐藏的是不是真的隐藏了吗?
我有一个从经典 asp 生成的简单 html 标记:
<table>
<tr class="trClass">
<td>Hello </td>
</tr>
<tr class ="trClass">
<td>World!</td>
</tr>
</table>
如果我使用 Jquery 将属于 Hello 的 tr 设置为 hide(),它将隐藏。好的!
但是,当我使用这个 $('.trClass:visible').each(function() {alert('visible') }); 它显示输出“可见”两次。
这是为什么呢?
我的问题是我用选择框过滤列上的表格。但是在过滤之后,我需要对表中可见的那些行执行一些计算,但我现在得到所有行。
有什么想法吗?
/丹尼尔
I have this simple html markup generated from classic asp:
<table>
<tr class="trClass">
<td>Hello </td>
</tr>
<tr class ="trClass">
<td>World!</td>
</tr>
</table>
If i set the tr belonging to Hello to hide() using Jquery it hides. Good!
But, when i use this $('.trClass:visible').each(function() { alert('visible') });
it shows the output 'visible' twice.
Why is this?
My problem here is that im filtering a table on a column with a selection box. But after filtering i need to perform some calculations on those rows that are visible in the table, but i get all rows right now.
Any ideas?
/Daniel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
:visible
选择器不会测试display
样式属性,您想要使用:hidden
改为 1.3.2 发行说明说:这些将正确选择您的可见行:
或:
或:
hide
将样式设置为display="none"
。 jQuery 1.3.2 的发行说明还指出:所以我猜在这种情况下
:visible
选择器错误地不匹配任何内容,因为根据执行的计算,行没有占用任何空间,尽管它们的 CSSdisplay
属性未设置为none
。相反,:hidden
可以正确匹配具有style="display:none"
的元素,因此对非:hidden
元素的测试效果很好。The
:visible
selector does not test thedisplay
style property, you want to use:hidden
instead, the 1.3.2 release notes say:These will correctly select your visible rows:
or:
or:
hide
sets the style todisplay="none"
. The release notes for jQuery 1.3.2 also say:so I guess in this case the
:visible
selector is erroneously not matching anything because the rows are not occupying any space according to the calculations performed, despite the fact that their CSSdisplay
property is not set tonone
. Conversely,:hidden
correctly matches elements withstyle="display:none"
so testing for non:hidden
elements works just fine.您发现了一个合法的错误。它在 1.3.2 中被破坏,但现在已在主干中修复。
根据重新注册:
我想你想知道......
You've found a legitimate bug. It's broken in 1.3.2 but now fixed in trunk.
According to Resig:
Thought you'd like to know...
不确定这是否重要,但是 hide() 不会设置
display: none;
而不是visible: hide
吗?这意味着隐藏行仍然可见,只是没有显示......Not sure if this matters, but doesn't hide() set
display: none;
and notvisible: hidden
? Meaning that a hidden row is still visible, it just isn't displayed...最有可能的是你的 trClass 与显示发生冲突: .hide() 设置的没有。
当标签同时具有类属性和样式属性时,仅应用。
你应该仔细检查你的 trClass 并从中取出 display: 内容。
most likely your trClass collides with the display: none that .hide() sets.
when a tag has both class attribute and style attribute only on will be applied.
you should inpsect closely your trClass and take out display: stuff from it.