jquery对css的更多设置

接下来介绍jq对HTML的标签追加类名和增加内容。
如果不加jq,代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        .box2{
            background: red;
            width: 100px;
            height: 100px;
        }
    </style>

</head>
<body>

<div id="box1"></div>
<ul>
    <li></li>
    <li></li>
    <li></li>
</ul>
<ul>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
</ul>
</body>
</html>

在这里插入图片描述
div和ul li标签没有写任何内容,也没有赋予类名box2
增加jq代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        .box2{
            background: red;
            width: 100px;
            height: 100px;
        }
    </style>
    <script src="jquery-1.12.4.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#box1').addClass('box2');//追加样式(增加类名)
            $('ul li').html('lll')//增加内容

       })
    </script>
</head>
<body>

<div id="box1"></div>
<ul>
    <li></li>
    <li></li>
    <li></li>
</ul>
<ul>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
</ul>
</body>
</html>

运行效果:
在这里插入图片描述
通过追加类名使得上面的css样式可以再div标签执行,".html()"可以在选择的标签中增加需要的内容。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值