如何使用 jQuery 更改 CSS?
jqueryweb developmentfront end technology
要使用 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>
相关文章
打印
下一节:解释 jQuery.append()、jQuery.prepend()、jQuery.after() 和 jQuery.before() 方法。 ❯❮ 上一节:如何使用 jQuery 查找水平滚动容器中元素的左侧位置?

