-1

最近誰かがラジオ ボタンの問題を修正するためにこのコードをくれました。完全に動作しますが、ラジオ ボタンのグループをさらに除外するにはどうすればよいですか?

「lunch_fruitjuice」と「lunch_desserts」も除外したい

$(function(){
    // cache the selector for all target radio buttons for later use
    var targetRadioButtons = $("input:radio").not("input:radio[name=lunch_desserts]");

    targetRadioButtons.change(function(){
        var currentGroupName = $(this).prop("name");       

        // remove selected state from other items
        targetRadioButtons.not(this).prop('checked', false);
    });
})

ありがとう

4

4 に答える 4

1
var targetRadioButtons = $("input:radio").not("input:radio[name=lunch_desserts]").not("input:radio[name=lunch_fruitjuice]");
于 2013-10-29T14:55:40.317 に答える
0

特定のラジオ ボタンを選択から除外する場合は、除外するラジオ ボタンにクラスを追加する必要があります。このような:

HTML

<div><input type="radio" name="lunch_desserts" class="exclude" value="Jello"/> Jello</div>
<div><input type="radio" name="lunch_desserts" value="Pudding"/> Pudding</div>
<div><input type="radio" name="lunch_desserts" class="exclude" value="Candy"/> Candy</div>
<div><input type="radio" name="lunch_fruitjuice" value="Apple Juice"/> Apple Juice</div>
<div><input type="radio" name="lunch_fruitjuice" class="exclude" value="Orange Juice"/> Orange Juice</div>
<div><input type="radio" name="lunch_fruitjuice" value="Guava Juice"/> Guava Juice</div>

JavaScript

// Select radio buttons that do not have the exclude class
var targetRadioButtons = $("input:radio:not(.exclude)");

// Test it by disabling just the targetRadioButtons
targetRadioButtons.attr("disabled", true);

デモ: http://jsfiddle.net/J2DXF/

于 2013-10-29T14:56:59.123 に答える