老师请检查,添加元素那里需要改进吗?

来源:4-10 自由编程

李知恩

2021-03-31 16:36:27

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

</head>

<body>

    <button>添加</button>

    <ul>

        <li>111</li>

        <li>222</li>

        <li>333</li>

        <li>444</li>

    </ul>



    <script type="text/javascript" src="../../lib/zepto.min.js"></script>

    <script type="text/javascript">

        $(document).ready(function(){

            $('ul').on('mouseenter','li',function(e){

                $(this).css('backgroundColor','red');

            });

            $('ul').on('mouseleave','li',function(e){

                $(this).css('backgroundColor','white');

            });

            $('button').click(function(e){

                $('ul').append("<li>555</li>")

            })



        })

    

    </script>


</body>

</html>


写回答

1回答

好帮手慕慕子

2021-03-31

同学你好,效果实现是对的,代码也很简洁,添加元素那里不需要改进了,继续加油,祝学习愉快~

0

0 学习 · 3299 问题

查看课程