简体   繁体   English

如何检查每个无线电组中的按钮是否被选中?

[英]How to check is the button is selected in each radio group?

I have 3 radio groups, and I want to check is the button is selected in each radio group. 我有3个广播组,我想检查一下是否在每个广播组中都选择了按钮。

For example I want something like that 例如我想要这样的东西

if (in each radio group one button is selected){
do something 
}

if ( one of RadioGroups have no selected button) {
Show something like Toast 
}

Read the three group by name. 按名称阅读三组。 Then iterator other it. 然后迭代器其他它。 Check .checked using conditional statement. 使用条件语句检查.checked。

var radios = document.getElementsByTagName('input1');
var value;
for (var i = 0; i < radios.length; i++) {
    if (radios[i].type === 'radio' && radios[i].checked) {
       // get value, set checked flag or do whatever you need to
       value = radios[i].value;       
    }
}

Suppose you have three radioButtons namely one two and three. 假设您有三个radioButton,即一二和三。 You could do like this. 你可以这样

if(one.isChecked() || two.isChecked() || three.isChecked()){

      //do something 


 }else if(!one.isChecked() || !two.isChecked() || !three.isChecked()){
     //do something
                    Toast.makeText(TourClass.this, "Passwords do not match", 
Toast.LENGTH_LONG).show();




  }

使用getCheckedRadioButtonId()RadioGroup查找选中的RadioButton

for each RadioGroup you write this: 为每个RadioGroup编写以下代码:

if (radioGroup.getCheckedRadioButtonId() == -1)
{
  // no radio buttons are checked
}
else
{
  // one of the radio buttons is checked
}

and you can also check answers here How to check if a radiobutton is checked in a radiogroup in Android? 您还可以在此处查看答案如何检查Android中的单选按钮中是否选中了单选按钮?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查单击按钮时是否选择了单选按钮? - How to check if radio buttons are selected on button click? 如何检查单选按钮是否在 Selenium WebDriver 中被选中? - How to check if the radio button is selected or not in Selenium WebDriver? 如何隐藏下一个按钮并在选择单选按钮时显示 - How to hide next button and show when radio group button is selected 在按钮组中选择了哪个单选按钮 - Which radio button is selected in a button group 如何在核心java程序中添加单选按钮组,以便一次只选择一个单选按钮? - How to add a radio button group in a core java program such that only one radio button is selected at one time? 选择单选组时未启用按钮 - Button not enabled when radio group are selected 在“按钮”上单击以检查是否选择了单选按钮 - On Button click to check whether the radio buttons are selected 从按钮组中获取所选单选按钮的名称 - get the name of the selected radio button from button group 多个广播组为每个组的键盘中的每个单选按钮提供快捷键 - multiple radio group give short cut key in keyboard for each radio button for each group java swing 如何将多个单选按钮分组到单选组下 - how to group multiple radio button under radio group
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM