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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 10:53:31  来源:igfitidea点击:

jQuery css() not working with visibility

jquerycss

提问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

Why not just use $('tr#target'). See jsFiddlehere.

为什么不直接使用$('tr#target'). 请参阅此处的jsFiddle

回答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:hiddencannot be considered :hidden.

查看文档:hiddenvisibility:hidden不能考虑带有 的元素:hidden

The solution would be to just target the trwithout the :hiddenselector, like so:

解决方案是只针对tr没有:hidden选择器的 ,如下所示:

$("tr#target").css("visibility","visible");