在 JQuery 中获取所选单选按钮的文本 [英] Get the text of the selected radio button in JQuery
本文介绍了在 JQuery 中获取所选单选按钮的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Jquery 中如何获取所选单选按钮的文本(不是值),如下所示
In Jquery How do I get the text (not values) for the selected radio button as shown below
<label> <input type="radio" name="Surv_Q1" value="20">5 - Excellent</label>
<label> <input type="radio" name="Surv_Q1" value="20">4 - Good</label>
我尝试了下面的代码,但没有用
I tried with the below code , but didn't work
$("input[name='Surv_Q"+i+"']:checked").next('label').text();
推荐答案
HTML:
<label> <input type="radio" name="Surv_Q1" value="20" data-name="5 - Excellent" checked="true">5 - Excellent</label>
<label> <input type="radio" name="Surv_Q1" value="20" data-name="4 - Good">4 - Good</label>
脚本:
$("input[name='Surv_Q1']:checked").data('name');
或者你不想在 HTML 中改变这个:
$("input[name='Surv_Q1']:checked").parent('label').text();
这篇关于在 JQuery 中获取所选单选按钮的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文