jQuery使用"hidden"和"visible"过滤器来判断页面元素是否可见,判断方式和css有些不同。jQuery是根据页面元素是否占用了空间来判断,而不是仅根据页面自身的属性。如果父元素是隐藏的,那么子元素也被认为是隐藏的,因为在页面中子元素是看不到,并且不占用空间的。
<div id="parentDiv" style="display: none;">
<div id="childDiv" style="display: block;"></div>
</div>
alert($('#childDiv').is(':hidden'));
alert的值为true。
欢迎搜索“谈谈IT”或扫描下方二维码关注微信公众号,第一时间获取最新文章(^_^)