如何用 jQuery 設定背景顏色?
要使用 jQuery 設定背景顏色,請使用 jQuery css() 屬性。我們將用 jQuery on() 滑鼠懸停設定背景顏色。
示例
你可以嘗試執行以下程式碼以在 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");
},
});
});
</script>
</head>
<body>
<p>Move the mouse pointer on the page to change the background color.</p>
</body>
</html>
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP