使用javascript获取相关的单选按钮标签文本 [英] get associated radio button label text using javascript

查看:53
本文介绍了使用javascript获取相关的单选按钮标签文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


<label for="radio1">
        This Radio Button 1 has a label associated with it.</label>
    <input type="radio" name="Radio" id="radio1" />

上面的代码具有一个标签和一个单选按钮,该标签使用for属性与单选按钮相关联.

above code has a label and radio button , the label is associated with radio button using the for attribute.

如果用户选择/选中相关的单选按钮,我想获取标签文本.

I would like to get the label text if user selects/checks the associated radio button.

推荐答案

如果使用jquery:

If your using jquery:

$('input[name="Radio"]').click(function(){ alert( $(this).prev('label').text() ) });

查看以下示例: http://jsfiddle.net/7FzQ9/

这篇关于使用javascript获取相关的单选按钮标签文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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