点击链接加入群聊【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>