如何在ExtJs中获得将应用于给定类列表的样式

How to get the styles that will be applied for a given class list in ExtJs

本文关键字:列表 样式 应用于 ExtJs      更新时间:2023-09-26

我尝试过Ext.DomHelper.createDom,但它创建了一个对象,而没有应用document stylesExt.util.CSS.getRules可以获得所有规则,但我必须手动确定哪些样式将被覆盖,哪些将被应用。

有没有一种简单的方法来获得给定类别列表的样式?

ExtJS没有提供获取元素所有样式的方法,但在元素被附加到dom:之后,您可以使用一点简单的旧javascript来实现

Ext.onReady(function() {
    var el = Ext.DomHelper.append(document.body, {
        tag: 'div',
        cls: 'foo'
    }),
    styles;
    if (window.getComputedStyle) {
        // use getComputedStyle if supported
        styles = window.getComputedStyle(el);
    } else {
        // fall back to currentStyle for IE8 and below
        styles = el.currentStyle;
    }
    // get a style
    alert(styles.fontSize);
});

当然,如果您只需要获得特定的样式,我建议使用Ext.ElementgetStyle()方法,因为它可以为您处理浏览器差异。