label通过for属性和radio,checkbox关联的checked值变化

点击链接加入群聊【IT学习技术交流会】:https://jq.qq.com/?_wv=1027&k=sJTOsjXG

通过for属性的label标签修改样式不会立即修改radio和checkbox的checked属性值,需要在radio和checkbox的表单元素上添加新的触法事件来修改checked属性值。

$(".requiredNotNull").click(function () {
    var type=$(this).attr("type");
    if(type == "radio"){
        if($(this).attr("checked")){

        }else{
            var name=$(this).attr("name");
            var inputList = document.getElementsByName(name);
            for(var i=0;i<inputList.length;i++){
                $(inputList[i]).attr("checked",false);
            }
            $(this).attr("checked",true);
        }
        console.log($(this).attr("checked"));
    }else if(type == "checkbox"){
        if($(this).attr("checked")){
            $(this).attr("checked",false);
        }else{
            $(this).attr("checked",true);
        }
        console.log($(this).attr("checked"));
    }

});

 

 

<input type="checkbox" class="gcs-checkbox requiredNotNull" id="${varNum.count }${bean.questionsId }" name="${bean.questionsId }" value="${choice }">
<label for="${varNum.count }${bean.questionsId }"></label>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值