作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一组单选按钮组。如何获取每个组的检查是或现在并将它们添加到数组中?
这是我到目前为止的想法:
我的jquery代码:
<script type="text/javascript">
$(function () {
$("#getinfo").click(function () {
$("input[name*=radio-choice-1]:checked").each(function () {
alert($(this).val());
});
});
});
</script>
和单选按钮
<fieldset data-role="controlgroup" data-type="horizontal" data-role="fieldcontain">
<input type="radio" name="radio-choice-1" id="radio-choice-1" value="choice-1" />
<label for="radio-choice-1">Yes</label>
<input type="radio" name="radio-choice-1" id="radio-choice-2" value="choice-2" />
<label for="radio-choice-2">No</label>
</fieldset>
<fieldset data-role="controlgroup" data-type="horizontal" data-role="fieldcontain">
<input type="radio" name="radio-choice-3" id="radio-choice-3" value="choice-3" />
<label for="radio-choice-3">Yes</label>
<input type="radio" name="radio-choice-3" id="radio-choice-4" value="choice-4" />
<label for="radio-choice-4">No</label>
</fieldset>
<fieldset data-role="controlgroup" data-type="horizontal" data-role="fieldcontain">
<input type="radio" name="radio-choice-5" id="radio-choice-5" value="choice-5" />
<label for="radio-choice-5">Yes</label>
<input type="radio" name="radio-choice-5" id="radio-choice-6" value="choice-6" />
<label for="radio-choice-6">No</label>
</fieldset>
<fieldset data-role="controlgroup" data-type="horizontal" data-role="fieldcontain">
<input type="radio" name="radio-choice-7" id="radio-choice-7" value="choice-7" />
<label for="radio-choice-7">Yes</label>
<input type="radio" name="radio-choice-7" id="radio-choice-8" value="choice-8" />
<label for="radio-choice-8">No</label>
</fieldset>
<a href="#" id="getinfo">getinfo</a>
最佳答案
您正在寻找名称中包含文本 radio-choice-1
的选中单选按钮 - 这永远只是一个单选按钮,因为它是全名。我认为您真正想要的是名称包含文本 radio-button-
的选中单选按钮,因此只需从选择器中删除 1
即可。
关于jquery - 如何在 jQuery Mobile 中获取选中的单选按钮值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9433871/
我是一名优秀的程序员,十分优秀!