체크 박스를 체크했을 때 관련 UL이 선택 사항에 따라 더 많은 옵션을 보여줄 수 있도록 폼 설정을했습니다. 작동하지만 사용자가 확인란의 레이블을 클릭 할 때만 작동합니다. 확인란을 클릭하면 예상대로 UL이 확장되지만 상자는 확인되지 않습니다.jQuery 체크 박스가 체크하지 않음
자바 스크립트 :
jQuery(document).ready(function()
{
jQuery('.toggleUL').click(function()
{
var checkbox = jQuery(this).find('input');
var ul = jQuery(this).next('ul');
if (ul.css('display') == 'block') { ul.find('input').attr('checked', false); }
if (checkbox.attr('checked') == false)
{
checkbox.attr('checked', true);
}
else
{
checkbox.attr('checked', false);
}
ul.slideToggle('slow'); return false;
});
});
HTML :
<label class="toggleUL"><input style="margin-right: 10px" type="checkbox" name="quoteWebsite" id="quoteWebsite" value="xxx" />xxx</label>
<ul style="list-style-type: none; display: none">
<li style="margin-left: 20px"><label><input style="margin-right: 10px" type="checkbox" name="quoteWebsite1[]" id="quoteWebsite1" value="xxx" />xxx</label></li>
<li style="margin-left: 20px"><label><input style="margin-right: 10px" type="checkbox" name="quoteWebsite1[]" id="quoteWebsite2" value="xxx" />xxx</label></li>
<li style="margin-left: 20px"><label><input style="margin-right: 10px" type="checkbox" name="quoteWebsite1[]" id="quoteWebsite3" value="xxx" />xxx</label></li>
</ul>
이 slideToggle() 함수가 제대로 작동하지 않을했다. 상자/레이블을 클릭하면 UL이 즉시 펼쳐집니다. 내가 멈출 수있는 유일한 방법은 'return false;'를 추가하는 것이 었습니다. 물론 체크 박스가 체크되지 않게한다. 그러므로 checkbox.attr().
해킹 된 코드입니다. 하지만 어떻게 체크 박스를 사용할 수 있습니까? >. <
이렇게하면 체크 박스가 전혀 선택되지 않습니다. 자체 또는 레이블 인 경우 클릭하지 마십시오. – spirax