2011-03-22 5 views
0

Ive의 라디오 버튼이 3 개 있습니다.
* 이메일 버튼을 클릭하면 이메일 텍스트 상자가 표시됩니다
* 컬렉션을 클릭하면 컬렉션 텍스트 상자 만 표시되고 다른 div는 숨겨집니다. 내가 어떻게 그럴 수 있니? 아래의 코드는 변경 사항을 보여 주지만 숨기지 않는 것처럼 보입니다! ID와jquery 라디오 버튼 표시/숨기기

<input type="radio" name="d_method" class="c_email"/>Email 
<input name="d_method" type="radio" class="c_collection"/>Colletion 
<input name="d_method" type="radio" class="c_post"/>Post 

3 숨겨진 사업부 :

<div id="c_email" style="display:none;"> 
    email textbox 
</div> 
<div id="c_collection" style="display:none;"> 
    collection textbox 
</div> 
<div id="c_post" style="display:none;"> 
    post textbox 
</div> 

및 JQuery와 :

$('.c_email').change(function() { 
     $('#c_email').stop().fadeIn(); 
    }, function(){ 
     $('#c_email').stop().hide(); 
    }) 
    $('.c_collection').change(function() { 
     $('#c_collection').stop().fadeIn(); 
    }, function(){ 
     $('#c_collection').stop().hide(); 
    }) 
    $('.c_post').change(function() { 
     $('#c_post').stop().fadeIn(); 
    }, function(){ 
     $('#c_post').stop().hide(); 
    }) 

답변

5

당신은 간단하게 할 수

$(':radio').change(function() { 
    var itemSelector = '#' + $(this).attr('class'); 
    $('div').stop().fadeOut(function() { 
     $(itemSelector).fadeIn(); 
    }); 
}); 

모든 국제 대회를 기반으로하는 클래스 이름은 당신의 ID와 같습니다. <div>

+0

감사합니다.;) – tonoslfx