zoukankan      html  css  js  c++  java
  • 1、清空所有,给当前添加/2、清空上一个,给当前添加。

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
            <script type="text/javascript" src="../ajax/ajaxdemo/js/jquery-2.1.4.min.js" ></script>
            <style>
                li{width: 20px;height: 20px;margin: 0 20px;background: yellowgreen;list-style: none;padding: 0;float: left;text-align: center;color: white;}
                .active{background: yellow;}
            </style>
        </head>
        <body>
            <ul>
                <li class="active">1</li>
                <li>2</li>
                <li>3</li>
                <li>4</li>
            </ul>
        </body>
    </html>
    <script>
    //    定义一个原来的初始的。
        var oldli=$('li')[0];
        $('li').bind('click',function(){
    //        请全部给当前添加
    //        $('li').removeClass('active');
    //        $(this).addClass('active');
            
    //        清除上一个,给当前添加
            $(oldli).removeClass('active');
            oldli=this;
            $(this).addClass('active');
        })
    </script>
  • 相关阅读:
    Codeforces 672D
    Codeforces 672C
    Codeforces 673D
    Codeforces 1181D
    Codeforces 1181C
    Codeforces 1011F
    Codeforces 1011E
    2020.1.3计导全面复习
    csp模拟题-201903
    CCF模拟题-201909
  • 原文地址:https://www.cnblogs.com/gaidalou/p/7804013.html
Copyright © 2011-2022 走看看