Jquery 可见性切换不起作用
只是一个简单的问题,有人可以告诉我哪里出了问题吗?我正在尝试切换类的可见性,但无法恢复其可见性。隐藏它很好:
if($(".ball").is(':visible') == true) {
$(".ball").css({ 'visibility': 'hidden'});
} else {
$(".ball").css({ 'visibility': 'visible'});
}
我不能使用切换,因为我需要保留该类但不被看到,切换会扰乱格式。
帮助会很好,谢谢。
Just a quick question, can someone tell me where this is going wrong, I'm trying to toggle visibility of a class but I can't restore its visibility. Hiding it is fine:
if($(".ball").is(':visible') == true) {
$(".ball").css({ 'visibility': 'hidden'});
} else {
$(".ball").css({ 'visibility': 'visible'});
}
I can't use toggle as I need the class to remain but not be seen, toggle will mess with formatting.
Help would be great, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
选择器“:visible”不能与可见性一起使用,只能与显示一起使用。
这是 jQuery 文档的片段http://api.jquery.com/visible-selector/:
试试这个:
这是一个示例 http://jsfiddle.net/eGVWM/2/
The selector ":visible" does not work with visibility, only with display
Here is a fragment of the jQuery documentation http://api.jquery.com/visible-selector/:
Try this:
Here is an example http://jsfiddle.net/eGVWM/2/
您可以选择具有
ball
类的所有元素,然后确定其隐藏位置:You can select all elements with the
ball
class and then determine where or not it is hidden:$(".ball").toggle();
也会切换,但使用display:none
进行操作。$(".ball").toggle();
will toggle too, but behaves usingdisplay:none
.可能不是您想要的,但它会隐藏具有 'ball' 类的元素
May not be what you are after but it will hide the elements with 'ball' class