如何获取收音机组中所选收音机的文本
正如标题所说 例如:
<input id="User_Type_0" type="radio" name="User_Type" value="1" checked="checked" />
<label for="User_Type_0">User1</label>
<input id="User_Type_1" type="radio" name="User_Type" value="2" />
<label for="User_Type_1">User2</label>
我怎样才能获取文本:User 1
as said in the title
for example:
<input id="User_Type_0" type="radio" name="User_Type" value="1" checked="checked" />
<label for="User_Type_0">User1</label>
<input id="User_Type_1" type="radio" name="User_Type" value="2" />
<label for="User_Type_1">User2</label>
how can I get the text:User 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
$('input:radio:checked').siblings('label:first').html()更新:
正如 Victor 在评论部分中指出的那样,前一个选择器将始终选择第一个标签。 next 函数应该可以工作:
$('input:radio:checked').siblings('label:first').html()UPDATE:
As pointed out by Victor in the comments section the previous selector will always select the first label. The next function should work:
这个怎么样?
how about this?
使用 .next();
use
.next();
这对我有用(我正在使用 jQuery Mobile):
DOM:
This works for me (I'm was using jQuery Mobile):
The DOM for this:
使用下一个 相邻选择器
+
怎么样?这是一个工作演示
What about using the next Adjacent Selector,
+
?Here's a Working Demo