给arron这个类加了背景,为何不起作用?

来源:3-4 DOM外部插入insertAfter()与insertBefore()

Owlapollo

2019-04-24 14:43

<!DOCTYPE html>

<html>


<head>

    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />

    <title></title>

    <script src="https://www.imooc.com/static/lib/jquery/1.9.1/jquery.js"></script>

    <style>

    .test1 {

        background: #bbffaa;

    }

    

    .test2 {

        background: yellow;

    }

    .arron{

        background:red;

        width:500px;

        height:300px;

    }       此处的定义为何无效?

    </style>

</head>


<body>

    <h2>通过insertBefore与insertAfter添加元素</h2>

    <button id="bt1">点击通过jQuery的insertBefore添加元素</button>

    <button id="bt2">点击通过jQuery的insertAfter添加元素</button>

    <div class="aaron">

        <p class="test1">测试insertBefore,不支持多参数</p>

    </div>

    <div class="aaron">

        <p class="test2">测试insertAfter,不支持多参数</p>

    </div>

    <script type="text/javascript">

    $("#bt1").on('click', function() {

        //在test1元素前后插入集合中每个匹配的元素

        //不支持多参数

        $('<p style="color:red">测试insertBefore方法增加</p>', '<p style="color:red">多参数</p>').insertBefore($(".test1"))

    })

    </script>

    <script type="text/javascript">

    $("#bt2").on('click', function() {

        //在test2元素前后插入集合中每个匹配的元素

        //不支持多参数

        $('<p style="color:red">测试insertAfter方法增加</p>', '<p style="color:red">多参数</p>').insertAfter($(".test2"))

    })

    </script> 

</body>


</html>


写回答 关注

1回答

  • 慕移动0426391
    2019-04-24 20:06:31
    已采纳

    同学,得认真检查代码了,aaron与arron,两个不同,一个a一个r

    Owlapo...

    哎呀妈呀,类名我也再三确认了都没看出来,真的要去洗洗眼了

    2019-04-25 15:36:22

    共 1 条回复 >

jQuery基础(二)—DOM篇

jQuery第二阶段开启DOM修炼,了解创建、插入、删除与替换

114008 学习 · 590 问题

查看课程

相似问题