跟之前的 CheckBoxList 例子很像,ASP.NET 的 RadioButtonList 在 HTML 也是由 Table + checkbox 組成,如果要用 JavaScript 判斷 User 選了那個 RadioBox,可以參考以下範例:

var selValue;
var table = document.getElementById("RadioButtonList1");

for(i=0;i<table.rows[0].cells.length;i++)
     if(table.rows[0].cells[i].childNodes[0].checked == true)
      selValue = table.rows[0].cells[i].childNodes[0].value;

要注意的是,這裡的RadioButtionList是用水平橫式的(Horizontal),如果用直式的(Vertical),table.rows[0].cells[i]要改為table.rows[i].cells[0]。

arrow
arrow
    全站熱搜

    felixhuang 發表在 痞客邦 留言(0) 人氣()