本文介绍了如何获得在jQuery移动检查单选按钮值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组单选按钮组。

I have a set of radio button groups. How can I get which is checked yes or now for each group and add them to array?

以下是我到目前为止的情况:

Here is what I came up so far:

我的jquery代码:

My jquery code:

<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 从您的选择器,它应该工作。

You're looking for the checked radio button with a name containing the text radio-choice-1 - that's only ever going to be one radio button, because it's the full name. I think what you actually wanted is the checked radio buttons with a name containing the text radio-button-, so just remove the 1 from your selector and it should work.

这篇关于如何获得在jQuery移动检查单选按钮值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 04:06