如何用 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>

更新時間: 2020-02-17

12K+ 瀏覽量

開啟你的 職業

完成本課程以獲得認證

開始
廣告