如何使用 . hide () 、.show () 或.toggle () 来切换元素的可见度 ?

如果元素可见或隐藏, 我如何测试 ?


当前回答

$( "div:visible" ).click(function() {
  $( this ).css( "background", "yellow" );
});
$( "button" ).click(function() {
  $( "div:hidden" ).show( "fast" );
});

api 文档: 可见选择器

其他回答

您可以尝试这个

$(document).ready(function() {
   var view = $(this).is(':visible');

   if(view) {
      alert("view");
                    // Code
   }
   else
   {
      alert("hidden");
   }
});

您可以使用隐藏选择器:

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

可见选择器 :

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

ebdiv 应设置为样式=“ display: noone; ” 。 它用于显示和隐藏 :

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

$( document). ready( { var discrible () { var revision = $ (' retemintion' ). is (': visible' ) ; 如果 (visible) { 备注 (“ 可见”) { 备注 ” ; // code} 其它 { 备警 (“ hidden” ) ;}} } ; & lt; 标注 src= "https://code. jquery. com/jquery-1.10.2. js; & gt;/ statimt>

您需要检查... 显示和可见度 :

if ($(this).css("display") == "none" || $(this).css("visibility") == "hidden") {
    // The element is not visible
} else {
    // The element is visible
}

如果我们自动检查$( thiss) 。 is (“: 可见”) , jquery check for both the things 自动检查 。