1. 程式人生 > >JS 設置復選框的選中與取消選中

JS 設置復選框的選中與取消選中

etc current author this fun 選中 true prop ssa

// 設置選中 function setCheckboxClick(obj) { if(obj == null) { $.messager.alert(‘警告‘, "請選擇要設置選中的項!",‘warning‘); } // alert(obj.value); var authorityId = obj.value; $.ajax({ type: ‘post‘, url: ‘getAuthorityByAuthorityId.action‘, data: {"authorityId" : authorityId}, dataType: ‘json‘, success:function(data) { console.info(data); var d = $.parseJSON(data); //$(":checkbox[name=authorityId]").prop("checked",false); // obj.checked = true; $(":checkbox[name=authorityId]").each(function(){ var currentAuthorityId = $(this).val(); for(var i = 0; i < d.length; i++) { if(currentAuthorityId == d[i].authorityId) { // $(this).prop("checked",true); if ($(this).prop("checked") == true) { $(this).prop("checked", false); } else { $(this).prop("checked",true); } } } }); }, error:function() { } });

JS 設置復選框的選中與取消選中