本文實(shí)例講述了js實(shí)現(xiàn)class樣式的修改、添加及刪除的方法。分享給大家供大家參考。具體分析如下:
比較常見的js前端功能,通過修改標(biāo)簽的className實(shí)現(xiàn)相應(yīng)的功能。
具體代碼如下:
<script>
$('.goods_sale_property').click(function(){//單獨(dú)a標(biāo)簽點(diǎn)擊添加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>
希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選