2011-06-06 60 views
0

可能顯示的文件:
php regexp: remove all attributes from an html tag
Remove style attribute from HTML tags如何使用jquery和PHP刪除所有樣式屬性?

EDITED:

例如我有以下內容:

<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> 

OR

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

如何才能做到這一點。 。任何幫助將感激和感激...

在此先感謝...

+0

紅色丸或藍色藥丸(jQuery或PHP)使您的選擇。 – dynamic 2011-06-06 09:38:40

+0

這真的取決於如果你想在PHP或jQuery中做到這一點。在PHP中,你可以使用preg_replace刪除樣式屬性...而在jQuery中,你可以使用.removeAttr(「style」); – 2011-06-06 09:39:07

+0

我需要知道它是如何使用它來完成的...任何人都可以解釋我... – Fero 2011-06-06 09:43:17

回答

9

jQuery的選擇是

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

PHP在評論提到

5

使用不選擇排除表

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

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

即使您的版本是完全有效的,我認爲在選擇器中使用否定使得它更加簡潔和易於理解。即'$( 「* [風格]:沒有(表)」)removeAttr( 「風格」);'。 – mkilmanas 2011-06-06 11:18:53