2011-07-27 3 views
1

라디오 버튼을 선택하면 텍스트를 변경하려고합니다. 라디오 버튼이 선택되면 상위 클래스에 클래스를 추가합니다. 이제 상위 요소 내부의 범위 텍스트를 변경해야합니다 (텍스트 "선택"을 "선택됨"으로 변경하려면 라디오 버튼이 체크 됨). 여기 내 코드는 다음과 같습니다클래스를 추가하고 라디오 버튼을 선택한 경우 텍스트를 변경하십시오.

$(document).ready(function(){ 
    //add the Selected class to the checked radio button 
    $('input:checked').parent().addClass("selected"); 
    //If another radio button is clicked, add the select class, and remove it from the previously selected radio 
    $('input').click(function() { 
     $('input:not(:checked)').parent().removeClass("selected"); 
     $('input:checked').parent().addClass("selected"); 
    }); 

}); 
      <td><div class="selectBtn"> 
       <input type="radio" name="group1" id="one" value="Falcon Air Trust"> 
       <span class="selectTxt">Select</span></div></td> 
      <td><div class="selectBtn"> 
       <input type="radio" name="group1" value="Atlantic Aviation"> 
       <span class="selectTxt">Select</span></div></td> 
      <td><div class="selectBtn"> 
       <input type="radio" name="group1" value="Reliance Aviation"> 
       Select</div></td> 

답변

3

$(document).ready(function(){ 
    //add the Selected class to the checked radio button 
    $('input:checked').parent().addClass("selected"); 
    //If another radio button is clicked, add the select class, and remove it from the previously selected radio 
    $('input').click(function() { 
     $('input:not(:checked)').parent().removeClass("selected").find("span").html("Select"); 
     $('input:checked').parent().addClass("selected").find("span").html("Selected"); 
    }); 

}); 
+0

완벽한보십시오! 매력처럼 작동했습니다, 감사합니다! – hbowman

관련 문제