Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
371 views
in Technique[技术] by (71.8m points)

javascript - 如何检查jQuery中是否隐藏了元素?(How do I check if an element is hidden in jQuery?)

It is possible to toggle the visibility of an element, using the functions .hide() , .show() or .toggle() ?(是可能的切换元件的可见性,使用函数.hide() .show().toggle())

How would you test if an element is visible or hidden?(您将如何测试元素是可见还是隐藏?)

  ask by Philip Morton translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Since the question refers to a single element, this code might be more suitable:(由于问题涉及单个元素,因此此代码可能更合适:)

// Checks css for display:[none|block], ignores visibility:[true|false]
$(element).is(":visible"); 

// The same works with hidden
$(element).is(":hidden"); 

Same as twernt's suggestion , but applied to a single element;(与twernt的建议相同,但适用于单个元素。)

and it matches the algorithm recommended in the jQuery FAQ(它与jQuery FAQ中推荐的算法匹配)

We use jQuery is() to check the selected element with another element, selector or any jQuery object.(我们使用jQuery is()与另一个元素,选择器或任何jQuery对象一起检查选定的元素。)

This method traverses along the DOM elements to find a match, which satisfies the passed parameter.(此方法遍历DOM元素以找到匹配项,该匹配项满足传递的参数。) It will return true if there is a match otherwise returns false.(如果存在匹配项,则返回true,否则返回false。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...