使用 jQuery 删除所有元素的背景颜色/图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4384213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 17:11:10 来源:igfitidea点击:
Remove background color/images for all elements with jQuery
提问by Ian McIntyre Silber
Is there a simple way to use jQuery to remove all background styles on a page? Specifically, need to remove background color and images.
有没有一种简单的方法可以使用 jQuery 删除页面上的所有背景样式?具体来说,需要去除背景颜色和图像。
回答by alex
Real simple with jQuery...
使用 jQuery 真的很简单...
$('*').css('background', 'transparent');
If you didn't have jQuery at your disposal...
如果您没有 jQuery 可供您使用...
var allElements = document.getElementsByTagName("*");
for (var i = 0, length = allElements.length; i < length; i++) {
allElements[i].style.background = "none";
}
回答by Sharon
$('*').css('background', 'transparent');
回答by pooja
HTML
HTML
<ul>
<li class="one"><a href="#"></a></li>
<li class="two"><a href="#"></a></li>
<li class="three"><a href="#"></a></li>
</ul>
CSS
CSS
.bg1 { background: url(images/red.jpg) repeat-x; background-color: #6c0000; }
.bg2 { background: url(images/orange.jpg) repeat-x; background-color: #5A2A00; }
.bg3 { background: url(images/blue.jpg) repeat-x; background-color: #00345B; }
JS
JS
$(document).ready(function(){
$("li.one").click( function(){ $
("body").removeClass('bg2 , bg3').addClass("bg1");
});
$("li.two").click( function(){ $
("body").removeClass("bg1 , bg3").addClass("bg2");
});
$("li.three").click( function(){ $
("body").removeClass("bg1 , bg2").addClass("bg3");
});
});