jquery只从6个表单中选择一个收音机 [英] jquery select only one radio from 6 forms

查看:67
本文介绍了jquery只从6个表单中选择一个收音机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有6个表单,每个表单有2个单选按钮。



我希望用户体验一次只能选择1个单选按钮。所以当他们遍历到另一个表格并检查单选按钮时。所有其他单选按钮将取消选择。

这是我迄今为止的尝试。

  $(document).ready(function(){
$('input [type = radio]')。prop('checked',false);

($'$'$('radio = checked'))。prop('checked',false); b $('input [type = radio]')。
});
});

我的想法是在开始时取消选择所有按钮。但在此之后,我对自己的逻辑感到困惑。



我想说的是,如果这个收音机是支票的,那么

,取消所有其他收音机。



在英语中它适合于一个句子,我怎样才能把它放入jquery?

$('input [type = radio]')。解决方案

  'input [type = radio]')。not(this).prop('checked',false); 
});

FIDDLE


I have 6 forms and each form has 2 radio buttons.

I want the user experience to be, that they can only select 1 radio button at a time. So when they traverse over into another form and check a radio button. all other radio buttons will deselect.

This is what I have so far in my attemps.

$(document).ready(function () {                 
  $('input[type=radio]').prop('checked', false);

  $('input[type=radio]').each(function (i) {                        
    $(this).not($('radio:checked')).prop('checked', false);                     
  });                   
});

my idea has been to deselect all buttons at the start. but after that i'm confused in my logic.

I want to say

if this radio is check, uncheck all other radios.

while in english it fits in one sentence, how can i get it into jquery?

解决方案

$('input[type=radio]').on('change', function(){
    $('input[type=radio]').not(this).prop('checked', false);
});

FIDDLE

这篇关于jquery只从6个表单中选择一个收音机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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