如何使用 jQuery 更改“text-decoration”屬性?


若要使用 jQuery 更改文字裝飾屬性,請使用 jQuery css() 屬性。

示例

您可以嘗試執行以下程式碼,將 text-decoration 屬性從下劃線更改為上劃線

線上演示

<!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({"text-decoration": "overline"});
        }
    });    
});
</script>
<style>
p {
   text-decoration: underline;
}
</style>
</head>
<body>
<p>Move the mouse pointer on the text to remove underline and add overline.</p>
</body>
</html>

更新日期:2019 年 12 月 11 日

736 次瀏覽

開啟您的 事業

完成課程獲得認證

開始
廣告
© . All rights reserved.