我有3个电台组,我想检查每个电台组中是否选择了按钮。
例如我想要那样的东西
if (in each radio group one button is selected){
do something
}
if ( one of RadioGroups have no selected button) {
Show something like Toast
}
答案 0 :(得分:0)
按名称阅读三组。然后迭代其他它。使用条件语句检查.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;
}
}
答案 1 :(得分:0)
假设您有三个radioButtons,即一个两个和三个。你可以这样做。
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();
}
答案 2 :(得分:0)
使用getCheckedRadioButtonId()
查找RadioButton
中已选中的RadioGroup
。
答案 3 :(得分:0)
你写的每个RadioGroup:
if (radioGroup.getCheckedRadioButtonId() == -1)
{
// no radio buttons are checked
}
else
{
// one of the radio buttons is checked
}
您还可以在How to check if a radiobutton is checked in a radiogroup in Android?
查看答案