如何使用jQuery更改'text-decoration'属性?

要使用jQuery更改文本修饰属性,请使用jQuerycss()属性。

示例

您可以尝试运行以下代码,将text-decoration属性从下划线更改为上划线:

<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.staticfile.org/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>