하위 하위 카테고리가있는 상위 하위 카테고리 체크 박스가 있습니다. 하위 카테고리는 상위 카테고리를 클릭 할 때만 표시되어야하며 상위 카테고리가 선택 취소되면 모든 하위 카테고리가 숨겨져 야합니다.jQuery 체크 박스 체크 박스 체크 박스 체크하지 않음
모든 것이 잘 작동하지만, 하위 및 하위 파일이 선택되었다고 가정합니다. 이제는 상위 부모가 선택 취소 된 경우 확인란을 선택하지 않은 상태에서 하위 선택 유지 확인란을 숨 깁니다.
여기 내 코드입니다.
$(function() {
$(':checkbox').change(function() {
$("input[type='checkbox']:checked").each(function() {
var inner_id = $(this).attr('id');
if (inner_id.search("parent") > -1) {
// $("input."+inner_id).attr('hidden','false')
$("."+inner_id).removeAttr("hidden");
}
});
});
});
$(function() {
$(':checkbox').click(function() {
var is_chk = $(this).attr('checked');
var its_id = $(this).attr('id');
if (is_chk != 'checked') {
$("."+its_id).attr('hidden', 'true');
}
});
});
이 html 코드는 다음과 같습니다.
<input type="checkbox" id="parent1" />parent<br/>
<input type="checkbox" class="parent1" disabled="true" />child1<br/>
<input type="checkbox" class="parent1" disabled="true"/>child2<br/>
<input type="checkbox" class="parent1" disabled="true"/>child3<br/>
<input type="checkbox" id="parent2" />parent<br/>
<input type="checkbox" class="parent2" disabled="true"/>child1<br/>
<input type="checkbox" class="parent2"
id="parent3" disabled="true"/>child2-parent<br/>
<input type="checkbox"
class="parent3" disabled="true"/>child1<br/>
<input type="checkbox"
class="parent3" disabled="true"/>child2<br/>
<input type="checkbox"
class="parent3" disabled="true"/>child3<br/>
<input type="checkbox"
class="parent3" disabled="true"/>child4<br/>
<input type="checkbox"
class="parent3" id="parent4" disabled="true"/>child5-parent<br/>
<input type="checkbox"
class="parent4" disabled="true"/>child1<br/>
<input type="checkbox"
class="parent4" disabled="true"/>child2<br/>
또는 여기에서 시도해 볼 수 있습니다.
은 체크 박스를 모두 확인하고 내 문제를 이해 부모를 클릭합니다. 감사합니다. .
내 프로젝트에서 시도한 실제 코드는 다음과 같습니다.
$(function() {
$(':checkbox').change(function() {
$("input[type='checkbox']:checked").each(function() {
//var inner_id = $(this).attr('id');
var inner_id = $(this).attr('value');
var parId1="input."+inner_id;
var parId2="."+inner_id;
$(parId1).removeAttr("disabled");
$(parId2).removeAttr("hidden");
});
});
});
$(function() {
$(':checkbox').click(function() {
var is_chk = $(this).attr('checked');
var its_id = $(this).attr('value');
//var parId2="#"+its_id;
var parId1="input."+its_id;
var parId2="."+its_id;
if(is_chk!='checked') {
$(parId1).removeAttr("checked");
$(parId1).attr('disabled','true');
$(parId2).attr('hidden','true');
}
});
});
당신의 바이올린으로 연주하는 시간이,하지만 어쩌면 이런 일을하려고하지 않는' .attr ('checked', false); ' –