我有3個無線電組,我想檢查是否在每個無線電組中選擇了按鈕。如何檢查每個收音機組中是否選擇了按鈕?
例如,我想這樣的事情
if (in each radio group one button is selected){
do something
}
if (one of RadioGroups have no selected button) {
Show something like Toast
}
我有3個無線電組,我想檢查是否在每個無線電組中選擇了按鈕。如何檢查每個收音機組中是否選擇了按鈕?
例如,我想這樣的事情
if (in each radio group one button is selected){
do something
}
if (one of RadioGroups have no selected button) {
Show something like Toast
}
的名字讀三組。然後迭代其他它。使用條件語句檢查.check。
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;
}
}
假設您有三個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();
}
使用getCheckedRadioButtonId()
在RadioGroup
找到檢查RadioButton
。
https://developer.android.com/guide/topics/ui/controls/radiobutton.html –