![](https://i-blog.csdnimg.cn/direct/af5098bfc2674a48bd9b4b85172628ff.png)
![](https://i-blog.csdnimg.cn/direct/215138776de5423494b6701576ba8f9c.png)
![](https://i-blog.csdnimg.cn/direct/45dcaded9b5a48c8b547803c5cfc21aa.png)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./JQuery.js"></script>
<style>
div{
width: 400px;
height: 400px;
background-color: rgb(16, 240, 240);
border: 1px solid red;
margin: auto;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
<script>
console.log($("div").css("background-color"));
$("div").click(function(){
if($(this).css("background-color") === "rgb(16, 240, 240)"){
$(this).css("background-color","antiquewhite");
}else{
$(this).css("background-color","red");
}
});
</script>
![](https://i-blog.csdnimg.cn/direct/d094a0676a7f40658ce092e38e60fbac.png)
![](https://i-blog.csdnimg.cn/direct/eed9934e6b524992be3f917ba72d8a28.png)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div{
width: 400px;
height: 400px;
background-image: linear-gradient( to right,rgb(21, 252, 9),yellow, rgb(245, 9, 9));
border: 1px solid red;
margin: auto;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
<script>
var div = document.getElementsByTagName("div")[0];
console.log("div");
div.onclick = function(){
if (div.style.backgroundImage === 'linear-gradient(to right, rgb(21, 252, 9), yellow, rgb(245, 9, 9))'){
div.style.backgroundImage = 'linear-gradient(to bottom, rgb(21, 252, 9), yellow, rgb(245, 9, 9))';
} else {
div.style.backgroundImage = 'linear-gradient(to right, rgb(21, 252, 9), yellow, rgb(245, 9, 9))';
}
}
</script>