获取元素的所有计算样式 [英] Get all computed style of an element

查看:67
本文介绍了获取元素的所有计算样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想得到所有的样式应用于一个元素,例如像chrome开发工具,你看到在右上部分称为计算风格我想得到所有的列表是有任何其他简单的方法来获取所有的列表和属性

i want to get all the style applyed to an element e.g like in chrome developer tool you have seen at top right section called "Computed Style" i want to get all the list is there any other simple way to get all the list and property

源代码

我试过这个javascript但它不是我想要的,我有手动写css属性

i tried this javascript but it is not what i want, i have to manual write css property

应用于元素之前或之前的样式

i just want all the style applied to a element earlier or by default

推荐答案

尝试使用此函数(更新您的jsFiddle );

Try using this function (updated your jsFiddle);

function getComputedStyle(elm, style) {
    var computedStyle;
    if (typeof elm.currentStyle != "undefined") {
        computedStyle = elm.currentStyle;
    }
    else {
        computedStyle = document.defaultView.getComputedStyle(elm, null);
    }
    return computedStyle[style];
}

getComputedStyle函数来自我是Javascript!

这篇关于获取元素的所有计算样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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