如何使用 jQuery 更改文字顏色?


要使用 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 年 2 月 17 日

1.2 萬+ 瀏覽

開啟您的 職業生涯

完成課程即可獲得認證

開始
廣告
© . All rights reserved.