【问题标题】:Extract all inline css of concernet html提取关注 html 的所有内联 css
【发布时间】:2012-03-29 16:16:28
【问题描述】:

我想提取相关html的所有内联样式。

例如,下面是要提取内联css的相关html:

<div id="concernedHtmlPortion" style="style1">
    <div style="style2">
    <div style="style3;style4">Hello World!!</div>
    <div></div>
</div>

有没有办法只使用root id="concernedHtmlPortion"提取所有style

提取结果应该是:style1,style2,style3,style4

请帮忙!!

【问题讨论】:

    标签: javascript jquery css html-parsing html-content-extraction


    【解决方案1】:
    var allStyles = [];
    $('#concernedHtmlPortion, #concernedHtmlPortion [style]').each(function() {
        allStyles.push($(this).attr('style').split(';'));
    });
    alert(allStyles);​
    

    Working DEMO

    【讨论】:

    • 不能按要求工作...当; 有多个样式并且您错过了包含#concernedHtmlPortion 元素的样式时,样式不会被拆分。看来你也是,能够误读问题! =)
    • 谢谢!这就是我想要的。虽然我已经使用了 childnode 概念,但是您提供的代码比我的要好。
    • @user966709。比除了答案。阅读this
    • 是的。我接受了答案。谢谢告诉我!下次我会记住的。
    • @user966709。您仍然可以接受旧问题的答案。没有时间限制。祝你好运!
    猜你喜欢
    • 2011-06-13
    • 1970-01-01
    • 2013-05-01
    • 2013-07-30
    • 2011-03-13
    • 2016-01-06
    • 2020-05-11
    • 2015-08-24
    • 2011-10-26
    相关资源
    最近更新 更多