jQuery .hide() 不隐藏元素
当完成将 json 解析为指定的 span 标签时,我想自动隐藏英制标签 currentimperial 和 Forecastimperial 但是当我尝试执行此操作
$('#currentimperial').hide();
$('#forecastimperial').hide();
并在 chrome 中查看结果并在控制台中查看时,我看到
style="display: none; "
它们实际上没有
style="display: inline; "
这里是我在 jsBin http://jsbin.com/efaguv/edit#javascript,html
感谢您收到的任何帮助。
When finished parsing the json into the specified span tags I wanted to automatically hide the imperial tags currentimperial and forecastimperial but when I try to do this use
$('#currentimperial').hide();
$('#forecastimperial').hide();
and view the result in chrome and look in the console I see that instead of
style="display: none; "
they actually have
style="display: inline; "
Here is my whole javascript and html on jsBin http://jsbin.com/efaguv/edit#javascript,html
Thanks for any help I recieve.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为问题是你没有考虑到你的 ajax 调用是异步的这一事实。
正在发生的事情的一个非常简单的示例:
因为(在完整代码中)ajax 成功回调使元素可见(使用
.fadeIn()
),最终结果是它们可见。您可以隐藏 ajax 成功回调中的元素吗?
I think the problem is that you haven't allowed for the fact that your ajax call is asynchronous.
A much simplified example of what's happening:
Because (in your full code) the ajax success callback makes the elements visible (using
.fadeIn()
) the end result is that they are visible.Can you instead hide the elements within that ajax success callback?
您可以使用
或
You can use
or
我有一个类似的问题,隐藏没有隐藏。我正在使用 Angular,发现指令在
display
样式属性上使用!important
css 功能,强制其保留为块并阻止 hide 将显示更改为无。elem.attr('style', 'display: none !important;');
I had a similar issue where hide was not hiding. I am using angular and found that a directive was using the
!important
css feature on thedisplay
style attribute forcing it to remain a block and preventing hide from changing the display to none.elem.attr('style', 'display: none !important;');