2011-07-27 67 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