获取附加到无线电的元素的值
get value of element which attached to radio
当我使用 jQuery 选择一对单选按钮中的单选按钮时,如何获取 .coefficient
的值?
<label class="bet-team-box" for="radio-1">
<input class="bet-main-input" id="radio-1" name="group1" type="radio">
<span class="fake-label">
<span class="team">
Midnight Sun Esports
</span>
<span class="img-box">
<img src="images/logo-team-04.png" alt="image description" width="20" height="20" />
</span>
<span class="coefficient">
12.43
</span>
</span>
</label>
您可以使用 closest()
获取父 label
元素,然后使用 find()
获取 coefficient
。试试这个:
$('.bet-main-input').change(function() {
var coefficient = $(this).closest('label').find('.coefficient').text();
// use variable here...
});
不确定这是否是最佳方式,但您可以像这样找到它。
$("#radio-1").click(function()
{
$($($(this).siblings()[0]).children('span.coefficient')).text();
});
当我使用 jQuery 选择一对单选按钮中的单选按钮时,如何获取 .coefficient
的值?
<label class="bet-team-box" for="radio-1">
<input class="bet-main-input" id="radio-1" name="group1" type="radio">
<span class="fake-label">
<span class="team">
Midnight Sun Esports
</span>
<span class="img-box">
<img src="images/logo-team-04.png" alt="image description" width="20" height="20" />
</span>
<span class="coefficient">
12.43
</span>
</span>
</label>
您可以使用 closest()
获取父 label
元素,然后使用 find()
获取 coefficient
。试试这个:
$('.bet-main-input').change(function() {
var coefficient = $(this).closest('label').find('.coefficient').text();
// use variable here...
});
不确定这是否是最佳方式,但您可以像这样找到它。
$("#radio-1").click(function()
{
$($($(this).siblings()[0]).children('span.coefficient')).text();
});