微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – 从样式中删除background-image

我如何从元素样式中删除background-image.我不想把它设置为none或0.我想完全删除它.它与在另一个类中定义的moz-linear-gradient相冲突.
<div style="background-image:url(http://domain.com/1.jpg); width:100px" class="mozgradient"></div>

解决方法

你有没有尝试过:
$(".mozgradient").css("background","");

将背景设置为空字符串应该删除内联样式,以便类和其他样式表设置生效,但不应影响其他类型的内置样式,如宽度. (在这种情况下,使用mozgradient类从所有元素中删除它可以防止您正在讨论的冲突.)

the jQuery .css() doco

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.

原文地址:https://www.jb51.cc/js/152828.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐