如何使用 jQuery 更改背景顏色?
要使用 jQuery 更改背景顏色,請使用 jQuery css() 屬性。我們將在滑鼠懸停時使用 jQuery on() 和 css() 方法更改背景顏色。
示例
你可以嘗試執行以下程式碼來學習如何使用 jQuery 更改背景顏色
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/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