js实现class样式的修改、添加及删除的方法
本文实例讲述了js实现class样式的修改、添加及删除的方法。分享给大家供大家参考。具体分析如下:
比较常见的js前端功能,通过修改标签的className实现相应的功能。
具体代码如下:
<table>
<tbody>
<tr>
<td>js实现class的样式的修改、添加、删除</td>
<td>
<ae_value="g_sn"ename="商品编码"class="goods_sale_property"href="javascript:void(0);">商品编码</a>
<ae_value="pdt_sn"ename="商品货号"class="goods_sale_property"href="javascript:void(0);">商品货号</a>
<ae_value="pdt_name"ename="规格名称"class="goods_sale_property"href="javascript:void(0);">规格名称</a>
</td>
</tr>
</tbody>
<tbody>
<tr>
<td><aonclick="selectAll()"style="color:#F00">全选</a></td>
<td><aonclick="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'); } }); functionselectAll(){//全选添class $('.goods_sale_property').each(function(i){ $(this).addClass('goods_sale_property_checked'); }); } functionselectNotAll(){//全选删除class $('.goods_sale_property').each(function(i){ $(this).removeClass('goods_sale_property_checked'); }); } </script>
热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短