gpt4 book ai didi

javascript - JQuery 获取所选 radio 的标签值

转载 作者:行者123 更新时间:2023-12-03 03:35:46 24 4
gpt4 key购买 nike

我有一些如下所示的 HTML:

 <label>
<input type="radio" onchange="routesearch2()" name="LargestMeeting" value="0" id="LargestMeeting_0" />
Less Than 5,000 sqft (<span id="lm1" class="detect lm1"></span>)</label>
<br />
<label>
<input type="radio" onchange="routesearch2()" name="LargestMeeting" value="5000" id="LargestMeeting_1" />
5,000 or more sqft (<span id="lm2" class="detect lm2"></span>)</label>
<br />
<label>
<input type="radio" onchange="routesearch2()" name="LargestMeeting" value="10000" id="LargestMeeting_2" />
10,000 or more sqft (<span id="lm3" class="detect lm3"></span>)</label>
<br />
<label>
<input type="radio" onchange="routesearch2()" name="LargestMeeting" value="20000" id="LargestMeeting_3" />
20,000 or more sqft (<span id="lm4" class="detect lm4"></span>)</label>
<br />
<label>
<input type="radio" onchange="routesearch2()" name="LargestMeeting" value="30000" id="LargestMeeting_4" />
30,000 or more sqft (<span id="lm5" class="detect lm5"></span>)</label>

我想(从函数内)获取选中的单选框的标签值。我认为它看起来像这样:

var mylabel = $("label[for='input[name=LargestMeeting]:checked']").text();
alert(mylabel)

我错过了什么?结果是空白的。

最佳答案

用这个

$("input[name=LargestMeeting]:checked").parent().text()

并清理空白,您可以添加

$.trim($("input[name=LargestMeeting]:checked").parent().text())

关于javascript - JQuery 获取所选 radio 的标签值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45867305/

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