设置单选按钮“选中” jquery中根据ID
我有两个同名的单选按钮,默认情况下选中一个。从 id 选择时如何选中或取消选中 jQuery 中的单选按钮?
我尝试过:
$('#radio1').attr('checked','checked');
$('#radio1').attr('checked', true);
似乎没有任何效果......有什么想法吗?
谢谢你!
I have two radio buttons with the same name, one is checked by default. How can you check or uncheck a radio button in jQuery when selecting from id?
I've tried:
$('#radio1').attr('checked','checked');
$('#radio1').attr('checked', true);
Nothing seems to work.. any ideas?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不能多次使用相同的 id (
#radio1
),请使用class
代替。id
应在每个页面的每个元素中使用一次。但是,如果您想选中/取消选中
点击
,您可能会喜欢:或者
You can not have same id (
#radio1
) more than once, use aclass
instead.The
id
should be used once per element per page.If you want to check/uncheck on
click
however, you may do like:Or
如果您有这样的收音机:
那么,要选中第二个并取消选中第一个:
反之亦然:
另一种想法是,您是否将收音机用作 JQuery UI 按钮?如果是这样,您可能还需要刷新它,例如:
If you have the radios like:
So, to check the second and uncheck the first one:
Viceversa:
Just another thought, are you using the radio as a JQuery UI button? If so you may also need to refresh it like:
好吧,如果您想从输入无线电中获取一个值以从数据库上传该值,您可以尝试使用以下简单的代码:
在其中放置变量“selValue”的名称,并在其中指定无线电组的名称“rbn 编号”。所有这些都在您工作和完成的功能内。
Well, if you wanna get a value from the input radio to upload this value from your database you can try with this simple code:
Where you put the name of the variable "selValue" and inside of this you specific the name of the radio group "rbnNumber". All this inside the function that you work and done.