如何使用 .hide()
、.show()
或 .toggle()
切换元素的可见性?
如何测试一个元素是可见
还是隐藏
?
最佳答案
由于问题涉及单个元素,因此此代码可能更合适:
// Checks CSS content for display:[none|block], ignores visibility:[true|false]
$(element).is(":visible");
// The same works with hidden
$(element).is(":hidden");
同twernt's suggestion , 但应用于单个元素;它matches the algorithm recommended in the jQuery FAQ .
我们使用 jQuery 的 is()用另一个元素、选择器或任何 jQuery 对象检查所选元素。该方法遍历 DOM 元素以找到满足传递参数的匹配项。如果匹配则返回true,否则返回false。
关于javascript - 如何检查元素是否隐藏在 jQuery 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/178325/