我有三个单选按钮在一组,因此:
<div class="form-check ml-4">
<input class="form-check-input" type="radio" name="1" id="1" value="First">
<label class="form-check-label" for="1">First</label>
</div>
<div class="form-check ml-4">
<input class="form-check-input" type="radio" name="1" id="2" value="Second">
<label class="form-check-label" for="2">Second</label>
</div>
<div class="form-check ml-4">
<input class="form-check-input" type="radio" name="1" id="3" value="Third">
<label class="form-check-label" for="3">Third</label>
</div>
字符串
使用jQuery,我如何检索组中选中的单选按钮的第n个子编号?
我试过这个:
(($(find("input[type=radio]:checked")).attr('nth-child()')))
型
2条答案
按热度按时间vwkv1x7d1#
也许有点晚,但你没有解释获得第n个孩子的目的。我的猜测是,你想选择单选按钮的值。
对于单选按钮组的名称,您可以只要求
form.n1.value
,其中n1是名称。请注意,id属性的值应该以字母(the id attribute)开头。
个字符
jq6vz3qz2#
您需要获取环绕单选按钮的
div
的位置,而不是按钮本身。nth-child
不是元素的属性。.index()
方法将返回元素在其兄弟中的位置。字符串