本文介绍了使用js在页面中的所有css类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望能够获取页面上所有css文件的所有类名。
是否存在任何可能性,或者我必须自己阅读并解析它。浏览器没有api吗?
i want to be able to get all the class names of all css files on the page.Is there any existing possibility or do i have to read it and parse it by myself. Isn´t there any api of the browser?
推荐答案
这可能是一个重复的请求吗?
is maybe a dulplicate request of this? How do you read CSS rule values with JavaScript?
function getStyle(className) {
var classes = document.styleSheets[0].rules || document.styleSheets[0].cssRules
for(var x=0;x<classes.length;x++) {
if(classes[x].selectorText==className) {
(classes[x].cssText) ? alert(classes[x].cssText) : alert(classes[x].style.cssText);
}
}
}
getStyle('.test')
这篇关于使用js在页面中的所有css类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!