判断一组checkbox/redio是否被选中,为其添加样式

业务场景:当一行中有一个CheckBox被选中,则为此行添加class。

<script type="text/javascript">
$(function(){
    $("input[type='radio']").click(function(){
       $(this).parent("td").parent("tr").addClass("info");
    });

 $("input[type='checkbox']").click(function(){
    var s = $("input[name='name']");
    var boxChecked=false;
    s.each(function(i) {
        if(this.checked==true){
           boxChecked=true;
        }
    });
    if(boxChecked){
        $(this).parent("td").parent("tr").addClass("info");
    }else{
        $(this).parent("td").parent("tr").removeClass("info");
    }
 });
});
</script>
posted @ 2019-09-17 16:32  ~清风煮酒~  阅读(284)  评论(0编辑  收藏  举报