如何使用jQuery更改背景颜色?

要使用jQuery更改背景颜色,请使用jQuerycss()属性。我们将使用jQueryon()css()方法更改鼠标悬停时的背景颜色。 

示例

您可以尝试运行以下代码,以了解如何使用jQuery更改背景颜色:

<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("body").on({
        mouseenter: function(){
            $(this).css("background-color", "gray");
        },  
       
        mouseleave: function(){
            $(this).css("background-color", "red");
        },
       
        dblclick: function(){
            $(this).css("background-color", "yellow");
        }
    });
});
</script>
</head>
<body>

<p>Double click and move the mouse pointer to change the background color.</p>

</body>
</html>