2025-02-10

 

第一種方法:

function submitData() {

    var tb = document.getElementById(IDArray[0]);   //獲取服務器控件GridView的ID

    if (tb)

     {

    var rows = tb.rows;

    for (var i = 1; i < rows.length; i++) {

        var id = rows[i].cells[1].innerText;

        var name = rows[i].cells[2].innerHTML;

        var oDropDownList = rows[i].cells[3].childNodes[0];

        var oText = oDropDownList.options[oDropDownList.selectedIndex].text;   //獲取GridView中下拉列表中選中的文本

        var oValue = oDropDownList.options[oDropDownList.selectedIndex].value;;   //獲取GridView中下拉列表中選中的值  

 }

    }

}

第二種方法:

 function submitData() {

    var tb = document.getElementById(IDArray[0]);

    if (tb.hasChildNodes) {

        if (tb.childNodes[0] != null) {

            var rowCount = tb.childNodes[0].childNodes.length;

            for (var i = 1; i < rowCount; i++) {

                var child = tb.childNodes[0].childNodes[i];

                var id = rowCount[i].cells[1].innerHTML;

                var name = child.childNodes[1].innerHTML;

                var oDropDownList = child.childNodes[2].childNodes[0];

                var oText = oDropDownList.options[oDropDownList.selectedIndex].text;

                var oValue = oDropDownList.options[oDropDownList.selectedIndex].value

            }

        }

    }

摘自 鄒瓊俊的專欄

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *