作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用星级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() );
不起作用...
最佳答案
您需要在选择器中使用 [name="star1"]
因为它是名称,或者 .star
因为它是类,而不是 star1
。您的表单 formComment
上可能有一个 ID,但由于它未包含在您的示例中,因此也在选择器中使用 starVin
:
jQuery.noConflict();
alert( jQuery('#starVin input[name="star1"]:checked').val() );
或
alert( jQuery('#starVin .star:checked').val() );
如果您想测试checked
,您可以使用is()
方法:
$('#starVin input[name="star1"]').each(function(){ alert($(this).is(':checked')); });
关于jquery 星级评定获取值单选隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13089246/
我是一名优秀的程序员,十分优秀!