7
如果元素样式属性很重要(设置谷style=""
或JS),如何删除它?如何删除重要的CSS属性?
removeProperty()
不起作用(jsfiddle):
elem.style.setProperty('background', '#faa', 'important');
elem.style.removeProperty('background'); // doesn't work
(最好是frameworkless的解决方案,它只有在Chrome工作。)
有趣寿说' removeProperty('background')'如果没有用'important'设置,它就会工作。 – Qtax 2012-03-15 02:52:10
太好了,'cssText'对我来说很有用。 +2 ;-) – Qtax 2012-03-15 03:12:39
看来,删除速记属性将删除所有未设置为“important”的相应“longhand”属性。那些被设置为“重要”(直接作为longhand属性或通过速记属性)的东西似乎必须明确地删除。我没有找到支持这一点的参考,但我猜是按设计。 – 2012-03-15 03:14:45