0

私は具体的になります:

交換方法

<style type="text/css">
   .class1 {font-weight:bold; font-size:10pt;}
   .class2 {font-weight:bold; font-size:12pt;}
   ...
   .classN {font-weight:bold; font-size:8pt; vertical-align:sub;}
</style>

<div class="class2" style="color:blue;">
   Bold Text
</div>

これとともに:

<div style="color:blue; font-weight:bold; font-size:12pt;">
   Bold Text
</div>

**注 - ノードは任意のノードである可能性があります - 属性の順序は気にしません。- クラス属性を削除する必要はありません

それを行うための HTML メソッド (C#) はありますか? 正規表現?何か案は?

前もって感謝します!

4

2 に答える 2

0

jquery を使用している場合は、次のプラグインを使用できます。

/*
 * getStyleObject Plugin for jQuery JavaScript Library
 * From: http://upshots.org/?p=112
 *
 * Copyright: Unknown, see source link
 * Plugin version by Dakota Schneider (http://hackthetruth.org)
 */

(function($){
    $.fn.getStyleObject = function(){
        var dom = this.get(0);
        var style;
        var returns = {};
        if(window.getComputedStyle){
            var camelize = function(a,b){
                return b.toUpperCase();
            }
            style = window.getComputedStyle(dom, null);
            for(var i=0;i<style.length;i++){
                var prop = style[i];
                var camel = prop.replace(/\-([a-z])/g, camelize);
                var val = style.getPropertyValue(prop);
                returns[camel] = val;
            }
            return returns;
        }
        if(dom.currentStyle){
            style = dom.currentStyle;
            for(var prop in style){
                returns[prop] = style[prop];
            }
            return returns;
        }
        return this.css();
    }
})(jQuery);

そして、このようなことを試してください

<div class="class2" style="color:blue;">
   Bold Text
</div>
<script type="text/javascript">
  var computedStyle;
  $("div[class^='class']").each(function(){
    computedStyle = $(this).getStyleObject();
    $(this).css(computedStyle);
    $(this).attr('class','');
  });
</script>
于 2012-04-13T16:36:38.303 に答える
0

このツールを使用して、HTML/CSS をインライン CSS に変換します。=

http://inlinestyler.torchboxapps.com

これは、HTML ベースのメールのスタイリングなど、必要な場合にのみ使用してください。

于 2012-04-13T16:37:42.203 に答える