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 οnclick="selectAll()" style="color:#F00">全选</a> </td>
            <td><a οnclick="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>

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值