首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Cobra/Lobo HTML渲染器访问DOM节点的CSS属性

如何使用Cobra/Lobo HTML渲染器访问DOM节点的CSS属性
EN

Stack Overflow用户
提问于 2009-12-01 23:17:04
回答 1查看 459关注 0票数 0

我正在尝试了解如何使用Cobra/Lobo工具包访问DOM节点(在本例中为节点)的CSS属性。我目前所掌握的是:

代码语言:javascript
复制
    UserAgentContext uacontext = new SimpleUserAgentContext();
    DocumentBuilderImpl builder = new DocumentBuilderImpl(uacontext);

    URL url = new URL(TEST_URI);
    InputStream in = url.openConnection().getInputStream();

    Reader reader = new InputStreamReader(in, "ISO-8859-1");
    InputSourceImpl inputSource = new InputSourceImpl(reader, TEST_URI);
    HTMLDocumentImpl d = (HTMLDocumentImpl) builder.parse(inputSource);
    HTMLCollection images = d.getImages();

    for (int i = 0; i < images.getLength(); i++) {

        HTMLElementImpl n = (HTMLElementImpl) images.item(i);
        AbstractCSS2Properties curr = n.getCurrentStyle();

        System.out.println("Image " + i + ": " + curr.getPropertyValue("background-color"));
    }

现在,这似乎只给了我直接设置的样式,而不是继承或计算的样式。我怎么也能得到这些呢?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2009-12-01 23:34:53

我希望您需要使用Class HTMLElementImplgetComputedStyle方法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1826843

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档