2013-08-12 8 views
0

내 jQuery 코드를 작동하지 않는 함수 내가 함수 내에서 코드를 유지하고 전화를 해달라고하면 잘 작동하지만 함수로 함수 내에서JQuery와 방법은 잘 작동하지만로 만들 때

<script> 
    $(document).ready(function(){ 
     $("input:radio").change(function(){ 
     checkResult(); 
     }); 
    }); 
     function checkResult() 
     { 
     $this=$(this).parent("div.QA"); 
     $this.slideUp(); 
     } 

</script> 

답변

4

때문에 this 작동하지 않음 this 다시 수 있도록, checkResult을 콜백으로 - 별도의 함수로 작성되기 때문에 매개 변수

$(document).ready(function(){ 
    $("input:radio").change(function(){ 
     checkResult(this); 
    }); 
}); 
function checkResult(el) { 
    var $this = $(el).parent("div.QA"); 
    $this.slideUp(); 
} 
+0

확인 문제가 해결되었습니다. – TaraGurung

0

함수 이름을 통과 클릭 한 요소를 통과, 클릭 한 radio 요소를 참조하지 않습니다 변경된 요소에 적용됩니다.

$(document).ready(function(){ 
    $("input:radio").change(checkResult); 
}); 
function checkResult() 
{ 
    $this=$(this).parent("div.QA"); 
    $this.slideUp(); 
}