热门关键字:
jquery > jquery教程 > jquery教程 > 使用jQuerycss方法

使用jQuerycss方法

279
作者:管理员
发布时间:2021/2/4 14:03:50
评论数:0
转载请自觉注明原文:http://www.jq-school.com/Show.aspx?id=3828
您可以使用jQuerycss()方法将新CSS属性添加到元素,或使用jQuery动态修改现有属性值。


让我们尝试以下示例,以了解此方法的基本原理:


例试试这个代码»
<!DOCTYPE html>
<html lang="en">
<head>
<title>jQuery Add CSS Property Dynamically</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
    $(document).ready(function(){
        $("h1").css("color", "red");
        $("p").css({
            "background-color": "yellowgreen",
            "font-weight": "bold"
        });
    });
</script>
</head>
<body>
    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>
</body>
</html>




如果您觉得本文的内容对您的学习有所帮助:支付鼓励



关键字:jQuery
友荐云推荐