gpt4 book ai didi

jquery - 如何在 jQuery Mobile 中获取选中的单选按钮值?

转载 作者:行者123 更新时间:2023-12-01 02:13:59 25 4
gpt4 key购买 nike

我有一组单选按钮组。如何获取每个组的检查是或现在并将它们添加到数组中?

这是我到目前为止的想法:

我的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 即可。

Working DEMO

关于jquery - 如何在 jQuery Mobile 中获取选中的单选按钮值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9433871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com