2

私は星の評価を使用していますhttp://www.fyneworks.com/jquery/star-rating/

フォームを送信した後、ユーザーが非表示のラジオの値を確認する方法がわかりません

ここにコード:

         <div class="line mrgT mrgB" id="starVin">
            <input name="star1" type="radio" class="star" value="1" />
            <input name="star1" type="radio" class="star" value="2" />
            <input name="star1" type="radio" class="star" value="3" />
            <input name="star1" type="radio" class="star" value="4" />
            <input name="star1" type="radio" class="star" value="5" />
        </div>

私はこれを試してみます

alert( $('#formComent .star1:checked').val() );

動作しません...

4

3 に答える 3

5

これは名前であるため、またはクラスであるため[name="star1"]、セレクターで使用する必要があります。のフォームにIDがある場合がありますが、IDは例に含まれていないため、セレクターでの使用も同様です。.starstar1formCommentstarVin

jQuery.noConflict();
alert( jQuery('#starVin input[name="star1"]:checked').val() );

また

alert( jQuery('#starVin .star:checked').val() );

http://jsfiddle.net/tayNH/

テストする場合は、次の方法checkedを使用できます。is()

$('#starVin input[name="star1"]').each(function(){ alert($(this).is(':checked')); });
于 2012-10-26T14:54:13.847 に答える
0

マークアップに基づいて、必要だと思います$('#starVin input[name="star1"].star:checked').val()(コンテナーdivのIDを「#formComent」から「#starVin」に変更し、名前の特異性「[name = "star1"]」を追加し、「:checked」フィルターをセレクターに移動してから値。

実用的な例については、私のjsfiddleを参照してください

于 2012-10-26T15:06:25.680 に答える
0

ラジオボタンとして評価星がある場合、その評価星の値を取得するには、次のコードを記述しました。そしてそれは私にとってはうまくいきます。これは私のhtmlとjqueryのコードです。

<fieldset class="rating">
    <input type="radio" class="get_value" id="star5" name="rating" value="5" /><label class = "full" for="star5" title="Awesome - 5 stars"></label>
    <input type="radio" class="get_value" id="star4half" name="rating" value="4 and a half" /><label class="half" for="star4half" title="Pretty good - 4.5 stars"></label>
    <input type="radio" class="get_value" id="star4" name="rating" value="4" /><label class = "full" for="star4" title="Pretty good - 4 stars"></label>
    <input type="radio" class="get_value"id="star3half" name="rating" value="3 and a half" /><label class="half" for="star3half" title="Meh - 3.5 stars"></label>
    <input type="radio" class="get_value" id="star3" name="rating" value="3" /><label class = "full" for="star3" title="Meh - 3 stars"></label>
    <input type="radio" class="get_value" id="star2half" name="rating" value="2 and a half" /><label class="half" for="star2half" title="Kinda bad - 2.5 stars"></label>
    <input type="radio" class="get_value" id="star2" name="rating" value="2" /><label class = "full" for="star2" title="Kinda bad - 2 stars"></label>
    <input type="radio" class="get_value" id="star1half" name="rating" value="1 and a half" /><label class="half" for="star1half" title="Meh - 1.5 stars"></label>
    <input type="radio" class="get_value" id="star1" name="rating" value="1" /><label class = "full" for="star1" title="Sucks big time - 1 star"></label>
    <input type="radio" class="get_value" id="starhalf" name="rating" value="half" /><label class="half" for="starhalf" title="Sucks big time - 0.5 stars"></label>
</fieldset>

<script>
var star_rating = 0;
$(".get_value").click(function () {
    if($(this).prop("checked")) {
        star_rating = $(this).val();
        console.log(star_rating);
    }
});
</script>
于 2018-03-19T11:49:07.100 に答える