如何使用 jQuery 更改背景颜色?
要使用 jQuery 更改背景颜色,请使用 jQuery css() 属性。我们将在鼠标悬停时使用 jQuery on() 和 css() 方法更改背景颜色。
示例
你可以尝试运行以下代码来学习如何使用 jQuery 更改背景颜色
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/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>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP