문제

선택된 선택 옵션에 따라 특정 DIV를 표시하는 jQuery 스크립트가 있습니다.

다음은 다음과 같은 코드입니다.

jQuery.noConflict();
jQuery(document).ready(function() {
  jQuery.viewMap = {
    '' : jQuery([]),
    '1' : jQuery('.company_1'),
    '2' : jQuery('.company_2')
  };
  jQuery('#companyid').change(function() {
    jQuery.each(jQuery.viewMap, function() { this.hide(); });
    jQuery.viewMap[jQuery(this).val()].show();
  });
});

(예제 div)

<div class="company_1" style="display: none;">
  <input type="checkbox" name="classifications[Miner]" id="classifications[Miner]" /> Spec/Rough
  <input type="checkbox" name="classifications[Dealer]" id="classifications[Dealer]" /> Dealer
</div>

누군가 다른 옵션을 선택하면 div (.company_1, .company_2 등) 내부의 모든 확인란을 지우려고합니다. 그것이 말이된다면? :)

고맙습니다!

도움이 되었습니까?

해결책

"Checked"라는 속성을 제거하여 확인란을 선택 해제합니다. 노력하다:

jQuery.each(jQuery.viewMap, function() {
    this.hide();
    jQuery('input:checkbox', this).removeAttr('checked');
});

다른 팁

@David Andres는 코드가 작동하지 않아도 된 올바른 방향으로 나를 지적 해 주셔서 감사합니다.

$("div.company_1 input:checked").removeAttr("checked");

작동 한 일.

어때요 :

$("div.company_1 input[type:checkbox]").removeAttr("checked");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top