2012-08-30 4 views
0

왜 이것이 작동하지 않는지 이해할 수있는 사람이 있습니까?JQuery는 하나의 동작 만 수행합니다.

<div id="css-check" class="css-check tool-tip checkbox inline" ... 
    <input id="someid" name="somename" type="checkbox" value="somevalue" /> 
</div> 

$('.css-check').bind({ 
    click: function() { 
    $(this).toggleClass('clicked'); 
    this.children[0].click(); 
    }, 
    mouseenter: function() { 
    // do something on mouseenter 
    } 
}); 

첫 번째 작업 만 수행됩니다. 따라서 클래스는 토글되지만 div의 [0] 자식 인 체크 상자는 클릭되지 않습니다.

편집

이 작동합니다.

var $checkbox = $(this).children('input:first-child'); 
$checkbox.prop('checked', !$checkbox[0].checked); 
$(this).toggleClass('clicked'); 
+0

오신 것을 환영합니다 : 이것은 당신이 다음 확인란을 선택하려는 경우 사용, 클릭 이벤트를 트리거 스택 오버플로! 해결책으로 답을 추가하십시오. –

답변

0

변화 :

this.children[0].click(); 

에 :

$(this).children('input:first-child').click(); 

참고 :

$(this).children('input:first-child').attr('checked', 'true'); 
+0

흠, 정말로 작동하지 않았다. 그러나 내 질문 dows에서 편집 작업. 나를 올바른 방향으로 가리켜 주셔서 감사합니다. – Kasper

관련 문제