label标签for属性修改样式

通过label标签for属性修改样式时,不会立即修改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);
        }
    }else if(type == "checkbox"){
        if($(this).attr("checked")){
            $(this).attr("checked",false);
        }else{
            $(this).attr("checked",true);
        }
    }

});

 requiredNotNull可以不定义class

<input type="checkbox" class="requiredNotNull" id="checkedId" value="MZL">
<label for="checkedId">XXX</label>


 

发布了15 篇原创文章 · 获赞 2 · 访问量 210

猜你喜欢

转载自blog.csdn.net/u010777507/article/details/104928640