如何从元素样式中删除背景图像。我不想将它设置为无或 0。我想完全删除它。它与在另一个类中定义的 moz-linear-gradient
冲突。
<div style="background-image:url(http://domain.com/1.jpg); width:100px" class="mozgradient"></div>
最佳答案
你试过吗:
$(".mozgradient").css("background", "");
将背景设置为空字符串应该会删除内联样式,以便类和其他样式表设置生效,但它不应影响其他内联设置的样式,如 width
。 (在这种情况下,将它从具有 mozgradient
类的所有元素中删除可以防止您正在谈论的冲突。)
Setting the value of a style property to an empty string — e.g. $('#mydiv').css('color', '') — removes that property from an element if it has already been directly applied, whether in the HTML style attribute, through jQuery's .css() method, or through direct DOM manipulation of the style property.
关于javascript - 从样式中删除背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8032540/