4

重複の可能性:
jQuery でチェックボックスの値を取得する方法

私は次のフォームを持っています:

<form action="index.php">
    <div class="answer"><input type="radio" name="vote_answers" value="3615736&1047558" class="vote_answers"> 1</div>

    <div class="answer"><input type="radio" name="vote_answers" value="3615736&1121626" class="vote_answers"> 2</div>

    <div class="answer"><input type="radio" name="vote_answers" value="3615736&9910782" class="vote_answers"> 3</div>

    <input type="submit" name="submit" id="button_submit_vote" value="submit">
</form>

送信をクリックすると、チェックボックスの値を取得する必要があります

これは私のコードです:

$('#button_submit_vote').on('click',function() {
    if($('.vote_answers').is(':checked')){var id=$(this).val();}
    alert(id);
});

チェックボックスの値の代わりに、値「送信」を取得します。

4

2 に答える 2

5

これは、要素thisを参照するためです。セレクターbutton_submit_voteを使用できます。:checked

var id = $('.vote_answers:checked').val();
于 2013-01-27T19:07:17.017 に答える
1

あなたはそこまで行っていません:
$('.vote_answers:checked').val()

于 2013-01-27T19:08:04.490 に答える