确定是否CSS属性有一定的价值? [英] Determine if CSS attribute is a certain value?

查看:162
本文介绍了确定是否CSS属性有一定的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道如何确定一个jQuery语句像这样

Just wondering how to determine a jQuery statement like this

if( $("#test").css('display', 'block') == true) {
   return true;
}

基本上,我希望能够确定如果一个元素当前显示或通过隐藏显示:块的属性。

Basically, I want to be able to determine IF an element has is currently being shown or hidden via the "display:block" attribute ?

推荐答案

使用

if( $("#test").css('display') == 'block') {

我相当肯定的.css(),返回的计算值,总是会返回一个小写的结果 - 文档说这个什么都没有。为了使完全确定,你可以做一个

I'm fairly sure .css(), returning a calculated value, will always return a lower case result - the docs say nothing on this. To make totally sure, you could do a

if( $("#test").css('display').toLowerCase() == 'block') {

,而你可以依靠显示给出可靠的结果上,注意一些CSS属性的不会总是出现定义它们的方式即可。例如:

while you can rely on display giving reliable results, note that some CSS properties will not always show up the way they were defined. For example

a { color: red }

将变成 RGB(255,0,0); 在使用查询的.css()

这篇关于确定是否CSS属性有一定的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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