由于问题涉及单个元素,因此下面的代码可能更合适:
// 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()来用另一个元素、 Select 器或任何jQuery对象判断所选元素.该方法遍历DOM元素以找到满足传递参数的匹配项.如果存在匹配项,则返回true,否则返回false.