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>
4

2 回答 2

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

});
于 2011-07-27T18:50:52.630 回答
0

或者

http://jsfiddle.net/62DhL/1/

于 2011-07-27T18:54:02.503 回答