JS获取一行2列的表格数据

JS如下:

如何在JS中获取下拉框中的value和Text值呢?

获取Text值:

document.getElementById(s[0]).options[window.document.getElementById(s[0]).selectedIndex].Text;

获取value值:

document.getElementById(s[0]).options[window.document.getElementById(s[0]).selectedIndex].value

s[i] 数组中保护3个数据项:主键ID,控件ID,控件类型。

    function createTasks() {
        if (Page_ClientValidate()) {
            var rows = document.getElementById('EidtTable').rows;
            var result = '';
            var str = "<%=str%>"
            var arry = str.split(";");
            for (var i = 0; i < arry.length; i++) {
                var s = arry[i].split(",");
                switch (s[1]) {
                    case "TextBox":
                        var rowString = s[2]+"_"+document.getElementById(s[0]).value + ',';
                        break
                    case "radiobuttonlist":
                        var list = document.getElementById(s[0]).getElementsByTagName("input");
                        var strData = "";
                        for (var j = 0; j < list.length; j++) {
                            if (list[j].type == "radio") {
                                if (list[j].checked) {
                                    var rowString = s[2] + "_" + list[j].value + ',';
                                }
                            }
                        }
                        break;
                    case "TexBoxM":
                        var rowString = s[2] + "_" + document.getElementById(s[0]).value + ',';
                        break
                    case "DateTime":
                        var rowString = s[2] + "_" + document.getElementById(s[0]).value + ',';
                        break
                    case "FileUpload":
                        var rowString = s[2] + "_" + document.getElementById(s[0]).value + ',';
                        break
                    case "DropDownList":
                        var rowString = s[2] + "_" + document.getElementById(s[0]).options[window.document.getElementById(s[0]).selectedIndex].value + ',';
                        break
                    case "Hdf":
                        var hdf1 = document.getElementById(("hdf" + s[0] + "0")).value;
                        var hdf2 = document.getElementById(("hdf" + s[0] + "1")).value;
                        var rowString = s[2] + "_" + hdf1 + "-" + hdf2 + ',';
                        break
                    default:
                        break;

                }
                result = result + rowString;
             
            }
            document.getElementById("hdfValues").value = result;
          
        }

    }

你可能感兴趣的:(js)