使用jQuery检查元素是否为"display:none"或单击时是否阻止 [英] Check, using jQuery, if an element is 'display:none' or block on click

查看:101
本文介绍了使用jQuery检查元素是否为"display:none"或单击时是否阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查和排序隐藏的元素.是否可以找到所有属性display和值none的元素?

解决方案

您可以使用:visible 显示可见元素,并:hidden 查找隐藏元素.此隐藏元素的display属性设置为none.

hiddenElements = $(':hidden');
visibleElements = $(':visible');

要检查特定元素.

if($('#yourID:visible').length == 0)
{

}

如果元素占用了文档中的空间,则认为它们是可见的. 可见元素的宽度或高度大于零, 参考

您还可以将 is():visible

一起使用

if(!$('#yourID').is(':visible'))
{

}

如果要检查显示值,则可以使用 css()

if($('#yourID').css('display') == 'none')
{

}

如果使用显示,则display可以具有以下值.

显示:无

显示:内联

显示:阻止

显示:列表项

显示:内嵌广告

此处中检查所有可能的display值的完整列表. /p>

要使用JavaScript检查显示属性

var isVisible = document.getElementById("yourID").style.display == "block";
var isHidden = document.getElementById("yourID").style.display == "none"; 

I want to check and sort elements that are hidden. Is it possible to find all elements with attribute display and value none?

解决方案

You can use :visible for visible elements and :hidden to find out hidden elements. This hidden elements have display attribute set to none.

hiddenElements = $(':hidden');
visibleElements = $(':visible');

To check particular element.

if($('#yourID:visible').length == 0)
{

}

Elements are considered visible if they consume space in the document. Visible elements have a width or height that is greater than zero, Reference

You can also use is() with :visible

if(!$('#yourID').is(':visible'))
{

}

If you want to check value of display then you can use css()

if($('#yourID').css('display') == 'none')
{

}

If you are using display the following values display can have.

display: none

display: inline

display: block

display: list-item

display: inline-block

Check complete list of possible display values here.

To check the display property with JavaScript

var isVisible = document.getElementById("yourID").style.display == "block";
var isHidden = document.getElementById("yourID").style.display == "none"; 

这篇关于使用jQuery检查元素是否为"display:none"或单击时是否阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆