2014-03-27 60 views
-1

我似乎無法得到驗證代碼的一部分工作。在我的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

的可能重複的[檢查是否至少一個單選按鈕已被選定 - 的JavaScript(http://stackoverflow.com/questions/13060313/檢查-IF-AT-至少酮單選按鈕-過氣選定的JavaScript) – TylerH

回答

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 
}