jQuery css() 不适用于可见性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8685062/
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
jQuery css() not working with visibility
提问by Satch3000
In the code below I have changed show()
to css()
and modified the visibility. For some reason it doesn't show up onclick.
在下面的代码我已经改变show()
到css()
并修改了知名度。出于某种原因,它没有显示在点击。
Here is the HTML:
这是 HTML:
<td class="area">
<img src="/def.jpg" />
</td>
<tr id="target" style="visibility:hidden">
<td>This was hidden</td>
</tr>
and then the jQuery:
然后是jQuery:
$("td.area").on("click", "img", function(){
$("tr:hidden#target").css("visibility","visible");
});
采纳答案by Selvakumar Arumugam
回答by epignosisx
The selector :hiddendoes not work with visibilityjust with display. Here is the jQuery documentation http://api.jquery.com/hidden-selector/
选择:隐藏不工作,能见度只是显示。这是 jQuery 文档http://api.jquery.com/hidden-selector/
You have to try something different:
你必须尝试不同的东西:
var t = $("#target");
if(t.css("visibility") == "hidden"){
t.css("visibility", "visible");
}
回答by davissp14
I would personally write it like this.
我个人会这样写。
NOTE: I did not test this.
注意:我没有对此进行测试。
<style>
#target {visibility: hidden}
</style>
<script>
$('td.area').live('click', function(){
if ($('#target').is(":visible")) {
// Do something?
}
else {
// Make visible
$('#target').css('visibility', 'visible')
}
});
</script>
<td class="area"><img src="/def.jpg" /></td>
<tr id="target">
<td>This was hidden </td>
</tr>
回答by Purag
See the documentationfor :hidden
. Elements with visibility:hidden
cannot be considered :hidden
.
查看文档的:hidden
。visibility:hidden
不能考虑带有 的元素:hidden
。
The solution would be to just target the tr
without the :hidden
selector, like so:
解决方案是只针对tr
没有:hidden
选择器的 ,如下所示:
$("tr#target").css("visibility","visible");