zoukankan      html  css  js  c++  java
  • js实现class样式的修改、添加及删除的方法

    本文实例讲述了js实现class样式的修改、添加及删除的方法。分享给大家供大家参考。具体分析如下:

    比较常见的js前端功能,通过修改标签的className实现相应的功能。

    具体代码如下:

    <table>
    <tbody>
    <tr>
    <td>js实现class的样式的修改、添加、删除</td>
    <td>
     <a e_value="g_sn" ename="商品编码" class="goods_sale_property" href="javascript:void(0);">商品编码</a>
     <a e_value="pdt_sn" ename="商品货号" class="goods_sale_property" href="javascript:void(0);">商品货号</a>
     <a e_value="pdt_name" ename="规格名称" class="goods_sale_property" href="javascript:void(0);">规格名称</a>
    </td>
    </tr>
    </tbody>
    <tbody>
        <tr>
                <td><a onclick="selectAll()" style="color:#F00">全选</a> </td>
                <td><a onclick="selectNotAll()" style="color:#F00">全不选</a></td>
            </tr> 
        </tbody>
    </table>
     
    <script>
    $('.goods_sale_property').click(function(){//单独a标签点击添加class
        if($(this).hasClass('goods_sale_property_checked')){
            $(this).removeClass('goods_sale_property_checked');
        }else{
            $(this).addClass('goods_sale_property_checked');
        }
    });
    function selectAll(){//全选添class
     $('.goods_sale_property').each(function(i){
            $(this).addClass('goods_sale_property_checked');
     }); 
    }
    function selectNotAll(){//全选删除class
     $('.goods_sale_property').each(function(i){
    $(this).removeClass('goods_sale_property_checked');
     }); 
    }
    </script>
  • 相关阅读:
    static 关键字
    gitlab 配置到jenkins
    Eclipse下代码字体背景变红/变绿/变黄原因
    构造方法(和python初始化变量类似)
    面向对象(实际就像python跳用自己写的库那样)
    Python 的AES加密与解密
    break 和 continue 的用法
    for循环
    Eclipse快捷键
    java三元运算符
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/4961545.html
Copyright © 2011-2022 走看看