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

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

问题描述

如何在 JavaScript 或 jQuery 中循环遍历没有表单的单选按钮组?

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

推荐答案

这样的事情怎么办?(使用 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天全站免登陆