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 に答える