gpt4 book ai didi

javascript - 如何获取将应用于 ExtJs 中给定类列表的样式

转载 作者:行者123 更新时间:2023-11-28 13:41:59 25 4
gpt4 key购买 nike

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

是否有一种简单的方法来获取给定类列表的样式?

最佳答案

Ext JS 不提供获取元素所有样式的方法,但您可以在将元素附加到 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() 方法,因为它处理浏览器差异你。

关于javascript - 如何获取将应用于 ExtJs 中给定类列表的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12283475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com