如何使用JavaScript查找RadioButton的文本 [英] How to find the text of a RadioButton using javascript

查看:104
本文介绍了如何使用JavaScript查找RadioButton的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们.你能告诉我如何使用javascript查找RadioButton的文本吗?

在此先感谢..

Hi friends.. Can u please tell me how to find the text of a RadioButton using javascript.

Thanks in advance..

推荐答案

如果我们喜欢下面的代码,则可以将整个单选按钮获取为innerHTML,并且可以为单选按钮应用样式. />
If we do like the below code we can get the total radio button as innerHTML and we can apply styles for the radiobutton..

if(document.getElementById("rbId").checked)
{
    alert(document.getElementById("rbId").parentNode.innerHTML);
}



(或)

如果我们只想查找单选按钮的TEXT,则可以得到如下所示:



(or)

If we want to find only the TEXT of radiobutton means we can get like this:

alert(document.getElementById("rbId").parentNode.childNodes[1].innerHTML);



通过这样做,我们可以直接获取单选按钮的文本



By doing this we can directly get the text of radiobutton


诸如getElementById之类的东西可以为您提供帮助.
看看 http://www.tizag.com/javascriptT/javascript-getelementbyid.php [ ^ ].

[
Something like getElementById should help you out.
Take a look at http://www.tizag.com/javascriptT/javascript-getelementbyid.php[^].

This[^] is another good resource that should surely help you out.




我认为您需要使用getElementsByTagName(''label'').这可能会有所帮助.

http://shawpnendu.blogspot.com/2009/08/how-to-read-asp-radio-button-list.html [


I think you need to use the getElementsByTagName(''label''). This might help.

http://shawpnendu.blogspot.com/2009/08/how-to-read-asp-radio-button-list.html[^]


这篇关于如何使用JavaScript查找RadioButton的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆