2017-07-17 39 views

回答

2

如果要刪除整個style屬性,那麼你可以使用removeAttr('style');

$('span').removeAttr('style');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<span style="font-size: 8pt; color: #c00;">some texts</span>

如果要覆蓋該設置回默認,同時保留其他內嵌樣式,使用css('font-size', 'inherit');

$('span').css('font-size', 'inherit');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<span style="font-size: 8pt; color: #c00;">some texts</span>

+0

啊忘了'removeAttr'在這裏適用!作爲一個注意:這將刪除整個樣式 - 不是個別樣式 – ThisGuyHasTwoThumbs

+3

是的,在回答中說:'如果你想刪除整個樣式屬性...' –

+0

哈哈誤讀:) – ThisGuyHasTwoThumbs

-1

你的確可以,你可以使用.css() - 基本語法是:

$('selector').css('attr-name', 'value'); 

所以從跨度刪除的樣式,你會怎麼做:

$('span').css('font-size', ''); 
+0

我想你的意思'的.css()' – vi5ion

+0

你能指出在jQuery的'.style的文檔()'方法? – j08691

+0

哈哈,所以你是對的:p @ vi5ion – ThisGuyHasTwoThumbs

0

如果你想在任何的完全去除的內嵌樣式的html元素。

你可以通過jQuery提供的removeAttr方法。

$('span, div').removeAttr('style'); 
0

刪除內嵌樣式

$('span').removeAttr('style');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<span style="font-size: 8px; color: red">some texts</span>

更新在CSS

$('span').css({ 
 
    'font-size' : '20px', 
 
    color: 'blue' 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<span style="font-size: 8pt;">some texts</span>
0多個屬性

更新單個屬性使用CSS

$('span').css('font-size', '20px');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<span style="font-size: 8pt;">some texts</span>

相關問題