如何使用 jQuery 更改 CSS?
要使用 jQuery 更改 CSS,請使用 jQuery css() 方法。
示例
你可以嘗試執行以下程式碼來使用 jQuery 更改 CSS
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("h2").css("backgroundColor", "red");
$("#myid").css({
"backgroundColor": "gray",
"color": "white"});
$(".myclass").css("border", "2px solid black");
});
</script>
</head>
<body>
<h2>Heading 2</h2>
<p id="myid">This is some text.</p>
<div class="myclass">This is some text.</div>
</body>
</html>
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言
C++
C#
MongoDB
MySQL
JavaScript
PHP