开发者

How to get the innerText of RadioButtonList

I am able to use the following to ge开发者_运维知识库t the value of the selected radio button (of the radio button list rblReason)

var reasonId = $('#rblReason').find('input[checked]').val();   

How can I get the innerText of the radio button selected? ty


A radio button has no innerText, it is an empty element. What is your markup?

If you have a parent which contains the text you want:

<div> <input type="radio" name="thing" value="foo" /> Hello </div>

Then you could use:

var text= $('#rblReason input:checked').parent().text();

If you have a label element associated with the radio:

<input type="radio" name="thing" value="foo" id="thing-foo" />
<label for="thing-foo"> Hello </label>

then you could do:

var id= $('#rblReason input:checked').attr('id');
var text= $('label[for='+id+']').text();

Note, use :checked to see which checkbox/radio is currently selected. [checked] means testing that the element has a checked attribute, which will always return the initially-checked radio regardless of what the user has selected. [Except in IE, due to a bug.]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜