html:
<div class="tpc_content">
....
</div>
这是样式片段:
<style>
.tpc_content{ background: url('/aliwayWaterMaker.php') repeat !important; }
</style>
当我从 Chrome 中的开发人员工具在控制台调用 $('.tpc_content').css('background');
时,输出为:
"rgba(0, 0, 0, 0) url(http://www.aliway.com/aliwayWaterMaker.php) repeat scroll 0% 0% / auto padding-box border-box"
然后我尝试通过命令设置此 css 属性:$('.tpc_content').css('background', "rgba(20, 30, 40, 0)");
,之后我再次发送了 $('.tpc_content').css('background');
,输出仍然是:
"rgba(0, 0, 0, 0) url(http://www.aliway.com/aliwayWaterMaker.php) repeat scroll 0% 0% / auto padding-box border-box"
谁能告诉我如何在页面加载后通过 jquery 或 javascript 删除背景图片?
最佳答案
这是因为你的 !important 在你的 CSS 中....
骑乘
$('.tpc_content').attr('style', 'backround="url(http://www.aliway.com/aliwayWaterMaker.php) 重复滚动 0% 0%/auto padding-box border-框 !important"');
但是最好不要在你的 css 中使用 !important
关于javascript - 为什么我不能更改 css 中的背景属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21128484/