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;
          
        }

    }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM