0

こんにちは、これは私をぐるぐる回しています。

次のラジオ ボタンを検討してください。

<input type="radio" class="win" id="50" value="1" name="match1" />
<input type="radio" class="cover" id="50" value="2" name="match1" />

<input type="radio" class="win" id="51" value="1" name="match2" />
<input type="radio" class="cover" id="51" value="2" name="match2" />

<input type="radio" class="win" id="52" value="1" name="match3" />
<input type="radio" class="cover" id="52" value="2" name="match3" />

フォームが送信されたときに、選択されているボタンの ID を知りたいです。

一部のボタン ペアは、まったく選択されていない場合があります。

私は試した:

for (var x=1; x<4; ++x){

     if($('form #'+$(this).attr("id")+'input:radio[name=match'+x+']').prop('checked', true)){
          alert('Checked;);
     }

}

しかし、それは常に true に評価されます。

ありがとう

4

5 に答える 5

1

値を true に設定しています。を呼び出し,trueから削除します。prop

if($('form #'+$(this).attr("id")+'input:radio[name=match'+x+']').prop('checked')){
      alert('Checked;);
}

プロパティを設定すると、.prop('checked', true)それを呼び出した jQuery 要素が返され、true と評価されます。

于 2013-04-11T14:51:20.863 に答える
1

あなたはsettingただではなく、チェックされたプロパティですgetting

変化する

if($('form #'+$(this).attr("id")+'input:radio[name=match'+x+']').prop('checked', true))

if($('form #'+$(this).attr("id")+'input:radio[name=match'+x+']').prop('checked'))
于 2013-04-11T14:51:20.967 に答える
0

これであなたの質問に答えられると思います:

for (var i = 0, len = 4; i < len; i++) {
    if ( $('input[name=match' + i + ']:checked').val() ) {
        alert("Checked");
    }
}
于 2013-04-11T14:54:08.910 に答える