我试图在单选按钮上更改文本。我有它的工作,所以如果单选按钮被选中,我向父母添加一个类,现在只需要部分来更改父母内部的跨度文本(我希望文本“选择”更改为“已选择”,如果选中单选按钮)。这是我的代码:
$(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>
答案 0 :(得分: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");
});
});
答案 1 :(得分:0)