我有一组单选按钮组。如何获取每个组的yes或now选项,并将它们添加到数组中?
到目前为止,我的想法是:
我的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>发布于 2012-02-25 00:20:53
您将查找名称包含文本radio-choice-1的选中的单选按钮-这将只是一个单选按钮,因为它是全名。我认为您实际上需要的是选中的单选按钮,其名称包含文本radio-button-,因此只需从选择器中删除1,它就应该可以工作了。
发布于 2012-11-30 17:20:21
这样就可以完成工作了。我在我的项目中使用了以下代码。简单明了,如jQuery移动文档中所示。
$("input[type='radio']").bind( "change", function(event, ui) {
console.log($(this).val());
});https://stackoverflow.com/questions/9433871
复制相似问题