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

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


当前回答

下面的代码检查,如果元素隐藏在jquery或可见

// You can also do this...

        $("button").click(function(){
            // show hide paragraph on button click
            $("p").toggle("slow", function(){
                // check paragraph once toggle effect is completed
                if($("p").is(":visible")){
                    alert("The paragraph  is visible.");
                } else{
                    alert("The paragraph  is hidden.");
                }
            });
        });

其他回答

.is(":not(':hidden')") /*if shown*/
content.style.display != 'none'

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\可以\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

下面的代码检查,如果元素隐藏在jquery或可见

// You can also do this...

        $("button").click(function(){
            // show hide paragraph on button click
            $("p").toggle("slow", function(){
                // check paragraph once toggle effect is completed
                if($("p").is(":visible")){
                    alert("The paragraph  is visible.");
                } else{
                    alert("The paragraph  is hidden.");
                }
            });
        });

使用任何可见选择器或隐藏选择器检查粘度:

: 可见选择器 - jquery (“ : 可见”) 使用 : 隐藏选择器 - jquery (“ : 隐藏” )

使用.toggle () - 显示和隐藏元素

{{{{{{{{{{{{{{{}检查元素是否隐藏,并返回真实的虚假控制台.log($(“元素”)){{{{{{}}}检查元素是否可见,并返回真实的虚假控制台.log($(“元素”){{}}}{($(“元素”){}}}如果($(“元素”){}}}{{}}{{{}{{}}{{{{{}}可识别性{}}}}}($(“glegle}}}}}lock(funct}}}。

if($('#id_element').is(":visible")){
   alert('shown');
}else{
   alert('hidden');
}