如何在没有表单的情况下遍历单选按钮组? [英] How to loop through a radio buttons group without a form?

查看:112
本文介绍了如何在没有表单的情况下遍历单选按钮组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那么像这样的事情呢? ? (使用jQuery):

  $('input:radio')。each(function(){
if $(this).is(':checked')){
//你在这里有一个选中的单选按钮...
}
else {
//或者未选中一个在这里......
}
});

如果您喜欢,您也可以循环遍历所有选中的单选按钮:


$ b $

  $('input:radio:checked')。each(function(){
//遍历所有选中的单选按钮
});


How do I loop through a radio buttons group without a form in JavaScript or jQuery?

解决方案

What about something like this? (using jQuery):

$('input:radio').each(function() {
  if($(this).is(':checked')) {
    // You have a checked radio button here...
  } 
  else {
    // Or an unchecked one here...
  }
});

You can also loop through all the checked radio buttons like this, if you prefer:

$('input:radio:checked').each(function() {
   // Iterate through all checked radio buttons
});

这篇关于如何在没有表单的情况下遍历单选按钮组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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