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>
  • 相关阅读:
    【xinsir】githook之precommit分享
    node进程一些信号的意义
    ES6篇
    Webpack4篇
    Node篇
    Vuex篇
    WebStorage篇
    HTML5篇
    html5语义化标签大全
    emmet语法
  • 原文地址:https://www.cnblogs.com/gaidalou/p/7804013.html
Copyright © 2011-2022 走看看