show() 之后的 jQuery 假定 display:inline 是 :hidden。为什么?
在 jQuery 1.4.2 中,:hidden 过滤器不会过滤掉隐藏的元素,但我通过调用 show() 使其可见。过滤器假设它仍然是隐藏的。
这是错误还是我错过了什么?考虑以下代码:
$("td.ms-authoringcontrols > span[id*='_ParallelApprovers']:hidden:first").css("display")
"none"
$("td.ms-authoringcontrols > span[id*='_ParallelApprovers']:hidden:first").show()
Object
$("td.ms-authoringcontrols > span[id*='_ParallelApprovers']:hidden:first").css("display")
"inline" // ?? Let me scratch my head...
$("td.ms-authoringcontrols > span[id*='_ParallelApprovers']:hidden:first").is(":hidden")
true //element with "display:inline", visible in browser, but yet it is hidden
您期望的不是“内联”,而是“无”,因为使用了 :hidden 过滤器。
它的作用是从对象数组中选择第一个隐藏元素。每次我调用这些代码行时,我希望它们选择下一个隐藏元素(而不是我刚刚显示的元素)。
With jQuery 1.4.2, :hidden filter is not filtering out elements that were hidden, but i've made then visible by calling show(). Filter assumes it is still hidden.
Is this bug or am i missing something? Consider the following code:
$("td.ms-authoringcontrols > span[id*='_ParallelApprovers']:hidden:first").css("display")
"none"
$("td.ms-authoringcontrols > span[id*='_ParallelApprovers']:hidden:first").show()
Object
$("td.ms-authoringcontrols > span[id*='_ParallelApprovers']:hidden:first").css("display")
"inline" // ?? Let me scratch my head...
$("td.ms-authoringcontrols > span[id*='_ParallelApprovers']:hidden:first").is(":hidden")
true //element with "display:inline", visible in browser, but yet it is hidden
Instead of "inline", you would expect "none", because :hidden filter was used.
What it does is from an array of objects it selects first hidden element. Each time i call these lines of code, i expect them to select next hidden element (not the one i just showed).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设
.show()
线性发生,您的代码将是正确的。但是.show()
启动一个动画,并以显示的对象结束。如果您想在代码显示后执行代码,请使用带有动画长度和回调.show(100,function(){})
的替代形式。Your code would be correct assuming the
.show()
happened linearly. However.show()
starts an animation that ends with the object being shown. If you would like to execute code after it has shown use the alternative form with a animation length and a callback.show(100,function(){})
.