老师,这样对吗

来源:2-4 编程练习

木子小可爱

2019-09-25 08:24:22

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>习题</title>
    <style type="text/css">
    div {
        width: 200px;
        height: 200px;
        border: 1px solid red;
        text-align: center;
        line-height: 200px;
    }
    </style>
</head>

<body>
    <div>背景颜色为白色</div>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>    
    <script>
    //此处写代码
    $(document).ready(function(){

      $('div').mousedown(function(){
       $('div').eq($(this).index())
       .css({'background-color':'red'})
       .text('背景颜色为红色');});

      $('div').mouseup(function(){
        $('div').eq($(this).index())
        .css({'background-color':'yellow'})
        .text('背景颜色为黄色'); });
    });
    </script>
</body>
</html>

写回答

1回答

好帮手慕夭夭

2019-09-25

你好同学,实现的正确。继续加油哦。祝学习愉快!

0

0 学习 · 14456 问题

查看课程

相似问题