gpt4 book ai didi

jquery - 添加类并在选择时更改单选按钮上的文本

转载 作者:行者123 更新时间:2023-12-01 08:21:55 24 4
gpt4 key购买 nike

我试图在选择单选按钮后更改其上的文本。我让它工作,所以如果选中单选按钮,我会向父级添加一个类,现在只需要更改父级内跨度文本的部分(我希望文本“选择”更改为“选定”,如果单选按钮被选中)。这是我的代码:

$(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>

最佳答案

试试这个

$(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");
});

});

关于jquery - 添加类并在选择时更改单选按钮上的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6849541/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com