我可以使用console/alert/some-other-means一次读取所有CSS属性吗? [英] can I use console/alert/some-other-means to read out ALL CSS properties at once?
本文介绍了我可以使用console/alert/some-other-means一次读取所有CSS属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在调试iPad上的网站.在桌面上,元素显示,在iPad上,元素丢失.
I'm trying to debug a site on iPad. On desktop an element shows, on iPad it's missing.
问题:
有没有一种方法可以在一条类似于
Question:
Is there a way to output all CSS in one statement similar to
console.log( $('element').attr('class') );
还是找到要遍历所有CSS规则的错误属性的唯一方法?
or is the only way to find the faulty property to go through all CSS-rules one by one?
console.log( $('element').css('position') )
console.log( $('element').css('top') )
console.log( $('element').css('left') )
console.log( $('element').css('right') )
console.log( $('element').css('bottom') )
console.log( $('element').css('width') )
console.log( $('element').css('height') )
console.log( $('element').css('display') )
... you get the point...
感谢您的输入
推荐答案
您需要窗口. getComputedStyle :
getComputedStyle()给出所有CSS的最终使用值 元素的属性.
getComputedStyle() gives the final used values of all the CSS properties of an element.
每个现代浏览器(包括IE9)都支持.
Supported in every modern browser (including IE9).
一个简单的例子:
var style = window.getComputedStyle($('element').get(0), null);
这篇关于我可以使用console/alert/some-other-means一次读取所有CSS属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文