如何使元素的可见度.hide(), .show(),或.toggle()?

如果一个元素是visiblehidden?


当前回答

.is(":not(':hidden')") /*if shown*/

其他回答

您应该考虑的另一个答案是,如果您隐藏了一个元素,您应该使用jj 查询,但实际上没有隐藏它,而是删除了整个元素,但复制了它HTML HTML输入 jQuery 变量,然后您只需要测试屏幕上是否有这样的标记,然后使用普通if (!$('#thetagname').length).

ebdiv定 定 定style="display:none;"它既用于显示也用于隐藏:

$(document).ready(function(){
    $("#eb").click(function(){
        $("#ebdiv").toggle();
    });    
});

您可以使用hidden选择器 :

// Matches all elements that are hidden
$('element:hidden')

还有visible选择器 :

// Matches all elements that are visible
$('element:visible')

而不是撰写event每一单element,这样做:

$('div').each(function(){
  if($(this).css('display') === 'none'){
    $(this).css({'display':'block'});
  }
});

您也可以在以下输入中使用:

$('input').each(function(){
  if($(this).attr('type') === 'hidden'){
    $(this).attr('type', 'text');
  }
});
if($("h1").is(":hidden")){
    // your code..
}