This article describes how to modify, add and delete class styles by js. Share it for your reference. The specific analysis is as follows:
A more common front-end function of js, which can realize the corresponding function by modifying the className of the tag.
The specific code is as follows:
Copy the code as follows: <table>
<tbody>
<tr>
<td>js implements class style modification, addition and removal</td>
<td>
<a e_value="g_sn" ename="product code" href="javascript:void(0);">product code</a>
<a e_value="pdt_sn" ename="Product item number" href="javascript:void(0);">Product item number</a>
<a e_value="pdt_name" ename="Specification name" href="javascript:void(0);">Specification name</a>
</td>
</tr>
</tbody>
<tbody>
<tr>
<td><a onclick="selectAll()" style="color:#F00">Select all</a> </td>
<td><a onclick="selectNotAll()" style="color:#F00">No selection</a></td>
</tr>
</tbody>
</table>
<script>
$('.goods_sale_property').click(function(){// Click to add class in a tag alone
if($(this).hasClass('goods_sale_property_checked')){
$(this).removeClass('goods_sale_property_checked');
}else{
$(this).addClass('goods_sale_property_checked');
}
});
function selectAll(){//Select all class
$('.goods_sale_property').each(function(i){
$(this).addClass('goods_sale_property_checked');
});
}
function selectNotAll(){//Select all delete class
$('.goods_sale_property').each(function(i){
$(this).removeClass('goods_sale_property_checked');
});
}
</script>
I hope this article will be helpful to everyone's JavaScript programming.