如何使用 jQuery 更改文本颜色?
jqueryweb developmentfront end technology更新于 2026/1/15 21:22:17
要使用 jQuery 更改文本颜色,请使用 jQuery css() 方法。color 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(){
$("p").on({
mouseenter: function(){
$(this).css("color", "red");
}
});
});
</script>
</head>
<body>
<p>Move the mouse pointer on the text to change the text color.</p>
</body>
</html>

