本帖最后由 yuanwei0221 于 2013-05-15 12:41:27 编辑

解决方案 »

  1.   

    用jquery的选择器,这样:
    $("*").not("div").removeAttr("style");
      

  2.   


    var str = 
    str = str.replace(/<div style/g, '<div styles');
    str = str.replace(/(<.*)style=".*"(.*\/>)/g, '$1$2');
    str = str.replace(/<div styles/g, '<div style');没做测试,仅供参考
      

  3.   

    经过测试可以    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script>
        <script type="text/javascript"> 
        window.onload = function() {
         var obj = document.getElementById('divId');
         str = obj.innerHTML;
         //str = str.replace(/<div style/g, '<div styles');
    str = str.replace(/<div(.*)style/g, '<div$1styles');
    str = str.replace(/ style="[^"]*"/g, '');
    str = str.replace(/<div styles/g, '<div style');
    //str = str.replace(/<div styles/g, '<div style');
    obj.innerHTML = str;
    alert(str);
        }
        </script>
        <style type="text/css">    </style>
        </head>
        <body>
    <div id='divId'>
    <div style="color:#f00">这是DIV</div>
    <p style="color:#f00">这是P</p>
    <table style="color:#f00" border="1">这是TABLE</>
    </div>
        </body>
        </html>
      

  4.   

    上面还不行,看看这个    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script>
        <script type="text/javascript"> 
        window.onload = function() {
         var obj = document.getElementById('divId');
         str = obj.innerHTML;
         //str = str.replace(/<div style/g, '<div styles');
    str = str.replace(/<div(.*)style/g, '<div$1styles');
    str = str.replace(/ style="[^"]*"/g, '');
    str = str.replace(/<div(.*)styles/g, '<div$1style');
    //str = str.replace(/<div styles/g, '<div style');
    obj.innerHTML = str;
    alert(str);
        }
        </script>
        <style type="text/css">    </style>
        </head>
        <body>
    <div id='divId'>
    <div style="color:#f00">这是DIV</div>
    <p style="color:#f00">这是P</p>
    <table style="color:#f00" border="1">这是TABLE</>
    </div>
        </body>
        </html>
      

  5.   

    str = str.replace(/<div(.*)style/g, '<div$1styles');
    str = str.replace(/ style="[^"]*"/g, '');
    str = str.replace(/<div(.*)styles/g, '<div$1style');