检查 JQuery 中的单选按钮 [英] Checking a radio button in JQuery

查看:60
本文介绍了检查 JQuery 中的单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以编程方式检查给定值的单选按钮.表单有一个 id 并且输入类型显然有一个名称(但没有 id).到目前为止,我设法开始工作的唯一代码是:

I need to programmatically check a radio button given its value. The form has an id and the input type obviously has a name (but no id). The only code I managed to get working so far is:

$('input[name=my_name]:eq(1)').attr('checked', 'checked');

但我希望能够通过明确提供值来检查它.

But I'd like to be able to check it by explicitly providing the value.

推荐答案

所以你想选择具有特定值的收音机:

So you want to select the radio which has a particular value:

$('input[name=my_name][value=123]').attr('checked', true); // or 'checked'

这篇关于检查 JQuery 中的单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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