如何使用jquery以及PHP删除所有样式属性?

时间:2011-06-06 09:36:20

标签: php jquery html

  

可能重复:
  php regexp: remove all attributes from an html tag
  Remove style attribute from HTML tags

编辑:

例如,我有以下内容:

    <div style="text-indent: -76.5pt; margin: 0in 54.9pt 0pt 76.5pt;"><strong>Motion with Constant Acceleration</strong></div>

我需要使用jQuery和PHP 删除所有样式属性

我的输出应如下所示:

    <div style=""><strong>Motion with Constant Acceleration</strong></div>

    <div><strong>Motion with Constant Acceleration</strong></div>

如何做到这一点..任何帮助都会感恩和感激......

提前致谢...

2 个答案:

答案 0 :(得分:9)

jQuery选项将是

$('*[style]').attr('style', ''); 
// sets style attribute to empty string on all elements that have it

PHP在评论中引用

答案 1 :(得分:6)

使用not selector排除表

$("*[style]").not("table").removeAttr("style");

$("*[style]").not("table").attr("style", "");