我似乎无法获得一段验证码。在我的HTML页面上,我有一个单选按钮组(5个按钮,值为1-5)。在单击提交按钮时,我需要在Javascript中使用IF语句来检查是否已在组中的5个单选按钮中的一个中进行了选择。我怎么做到这一点?我写的制作单选按钮的代码是:
// Technical knowledge rating
oLabel = new sap.ui.commons.Label({
id : 'L-Tech',
text : '1. Technical Knowledge' });
var oRBG = new sap.ui.commons.RadioButtonGroup({
id : 'RBG-Tech',
tooltip : 'Rate the intern for Technical Knowledge (1 = Unsatisfied, 5 = Outstanding)',
columns : 5,
editable : true });
var oItem = new sap.ui.core.Item({
id : 'RB-Rate1',
text : '1',
tooltip : 'Unsatisfactory',
key : '1' });
oRBG.addItem(oItem);
var oItem = new sap.ui.core.Item({
id : 'RB-Rate2',
text : '2',
tooltip : 'Improvement Needed',
key : '2' });
oRBG.addItem(oItem);
var oItem = new sap.ui.core.Item({
id : 'RB-Rate3',
text : '3',
tooltip : 'Meets Expectations',
key : '3' });
oRBG.addItem(oItem);
var oItem = new sap.ui.core.Item({
id : 'RB-Rate4',
text : '4',
tooltip : 'Exceeds Expectations',
key : '4' });
oRBG.addItem(oItem);
oItem = new sap.ui.core.Item({
id : 'RB-Rate5',
text : '5',
tooltip : 'Outstanding',
key : '5' });
oRBG.addItem(oItem);
oMatrix.createRow(oLabel, oRBG);
oLabel = new sap.ui.commons.Label({
id : 'L-Text',
text : 'Notes (Optional):',
design : sap.ui.commons.TextViewDesign.L3 });
oCell = new sap.ui.commons.layout.MatrixLayoutCell({
colSpan : 4 });
oTA = new sap.ui.commons.TextArea({
id : 'TA-Text',
tooltip : 'Remarks',
editable : true,
wrapping : sap.ui.core.Wrapping.Off,
width : '200px',
height : '60px'
});
oLabel.setLabelFor(oTA);
oCell.addContent(oTA);
oMatrix.createRow(oLabel, oCell);
答案 0 :(得分:0)
if(document.getElementById('id_of_button1').checked) {
// radio button1 is checked
}else if(document.getElementById('id_of_button2').checked) {
// radio button2 is checked
}
else if(document.getElementById('id_of_button3').checked) {
// radio button3 is checked
}
else if(document.getElementById('id_of_button4').checked) {
// radio button4 is checked
}
else if(document.getElementById('id_of_button5').checked) {
// radio button5 is checked
}