论坛

标题: 看了视频似懂非懂,根据视频做的 [打印本页]

作者: 我要学代码    时间: 2018-7-31 09:42
标题: 看了视频似懂非懂,根据视频做的
看了视频似懂非懂,var a=$(this).index();$(".box").eq(a).css("background","green").siblings(".box").css("background","#CCC");不懂





<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>选项卡</title>
<style>
        .btn{  width:120px; height:50px; background:#CCC; text-align:center; line-height:50px; margin:20px 0;}
        .box{  width:400px; height:200px; background:#CCC;text-align:center;line-height:200px; margin:10px 0; font-size:20px}
</style>

        <script src="新建文件夹 (2)/jquery-3.0.0/jquery-3.0.0.min.js"></script>
    <script>
            $(function(){
                        $(".btn").click(function(){
                                var a=$(this).index();
                               
                               
                                $(this).css("background","red").siblings(".btn").css("background","#CCC");
                                $(".box").eq(a).css("background","green").siblings(".box").css("background","#CCC");
                               
                                })
                       
                       
                       
                        })
    </script>
</head>

<body>
    <div class="btn">按钮1</div>
    <div class="btn">按钮2</div>
    <div class="btn">按钮3</div>
    <div class="btn">按钮4</div>

    <div class="box">盒子1</div>
    <div class="box">盒子2</div>
    <div class="box">盒子3</div>
    <div class="box">盒子4</div>
</body>
</html>






欢迎光临 论坛 (http://bbs.qinxue.com/) Powered by Discuz! X3.1