該頁面有如下CSS:如何從元素中刪除所有繼承和計算的樣式?
input[type=text]
{
display: inline; padding: 7px; background-color: #f6f6f6; font-size: 12px; letter-spacing: 1px; border: 1px solid #aac7d1;
/* lots of other styles here... */
}
我有很多的文字輸入元素和以下內容:
<input type="text" id="txt1" />
我嘗試不同的風格適用於通過jQuery這個人文本框(txt1中) :
$('#txt1').removeClass().removeAttr('style').css({
'background-color': '#ff0000',
//lots of other styles here...
});
但是這些來自樣式表的樣式不能通過這種方式從元素中移除。 css規則input[type=text]
不是自定義類,所以removeClass()
在這裏不起作用,如果我是對的。
我想要做的是;完全刪除應用於元素txt1
的所有樣式。除了獲取所有計算樣式的列表並將其設置爲空之外,是否有某種方法可以執行此操作?
我認爲你是對的。我可以在循環內重置所有計算的樣式,但它不太合乎邏輯。 –