如何使用带有类名的 jquery 删除背景图像

Sha*_*gam 2 html jquery class background-image

我正在尝试使用 jquery 删除背景图像。但它没有发生,但使用相同的格式我可以更改背景颜色

<html>
<head>
<style>
h1 
{
background-image:url('paper.gif');
background-color:#cccccc;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){

     $("h1").each(function( index ) {
    $("."+$(this).attr("class")).css('background-image' , 'none');

    });

});
</script>
</head>


<h1 class="RED">This is a heading</h1>
<h1 class="YELLOW">This is a heading</h1>
<h1 class="RED">This is a heading</h1>
</html>
Run Code Online (Sandbox Code Playgroud)

Aar*_*ron 5

你不需要类部分,试试这个:

<script>
$(document).ready(function() {
    $("h1").css({'background-image' , 'none'});
});
</script>
Run Code Online (Sandbox Code Playgroud)

在 jQuery 中,您不是修改样式表,而是在应用样式表后修改 DOM,因此直接攻击元素即可。