Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery星级获得隐藏的价值无线电_Jquery - Fatal编程技术网

jquery星级获得隐藏的价值无线电

jquery星级获得隐藏的价值无线电,jquery,Jquery,我使用星级 我不明白如何让用户在提交表单后检查隐藏无线电的值 代码如下: <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" />

我使用星级

我不明白如何让用户在提交表单后检查隐藏无线电的值

代码如下:

         <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>

不起作用…

您需要在选择器中使用
[name=“star1”]
,因为它是名称,或者
.star
是类,而不是
star1
。您的
formComment
表单上可能有一个ID,但由于示例中未包含该ID,因此也可以在选择器中使用
in

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

如果要测试是否选中了
,可以使用
is()
方法:

$('#starVin input[name="star1"]').each(function(){ alert($(this).is(':checked')); });

基于您的标记,我认为您需要
$('#饥饿输入[name=“star1”].star:checked').val()
(将容器div的id从'#formComent'更改为'#饥饿',添加名称专用性'[name=“star1”]',并将“:checked”过滤器移动到选择器中,然后获取值


.

如果有评级星,作为单选按钮,要获得该评级星的值,我已经编写了以下代码。它的工作对我来说很好。 这是我的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>

var star_评级=0;
$(“.get_value”)。单击(函数(){
如果($(this).prop(“选中”)){
star_rating=$(this.val();
控制台日志(星级);
}
});

他有一个类。我可以在HTML中看到它。但他可能将它分配给多组输入;从这个示例中不可能知道。并且不起作用,因为所有输入在执行javascript后都被隐藏。结果:我得到错误:TypeError:$(“#饥饿.星:选中”)控制台中是否为空?您确定要加载jQuery库吗?是的,1.4.1.min我在同一页面上使用其他jQuery脚本警报是通过点击链接显示javascript函数调用。您如何使用此警报?您的
警报是否在
on('click',…)
处理程序中?请提供更多javascript代码。
$('#starVin input[name="star1"]').each(function(){ alert($(this).is(':checked')); });
<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>