jQuery检查元素是否具有特定的样式属性(显示) [英] jQuery check if element has a specific style property (display)
本文介绍了jQuery检查元素是否具有特定的样式属性(显示)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在函数中包含if / else语句。如何检查元素(例如#cadrage)是否具有显示样式属性?这是我在网上发现的,但是,它不起作用..
I need to have a if/else statement inside a function. How do you check if an element (e.g. #cadrage) has a display style property? This is what I have found around the net and yet, it is not working..
if( $('#cadrage').attr('style').display == 'block' ) {
// do something
} else {
// do something
}
推荐答案
jQuery .css()函数似乎就是你想要的。
The jQuery .css() function seems to be what you want.
if( $('#cadrage').css('display') == 'block' ) {
console.log('It equal block');
} else {
console.log('It did not equal block');
}
http://jsfiddle.net/SamMonk/FtP6W/
这篇关于jQuery检查元素是否具有特定的样式属性(显示)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文