0

在这个函数中,我将动态打印表格中的文本框。

        function makeTable() {

            row = new Array();

            cell = new Array();

            row_num = 20;

            cell_num = 4;

            tab = document.createElement('table');

            tab.setAttribute('id', 'newtable');

            tbo = document.createElement('tbody');

            tbo.setAttribute('id', 'tabody');

            for (c = 0; c < row_num; c++) {
                row[c] = document.createElement('tr');

                for (k = 0; k < cell_num; k++) {
                    cell[k] = document.createElement('td');

这用于打印表格中的文本框。

                        if (k > 0) {
                        cont = document.createElement("input");
                        cont.setAttribute('type', 'text');
                        cont.setAttribute('value', '');
                        cell[k].appendChild(cont);
                        row[c].appendChild(cell[k]);
                    }

                    else {
                        cont = document.createTextNode("0" + (c + 1));
                        cell[k].appendChild(cont);
                        row[c].appendChild(cell[k]);
                    }
                }

                tbo.appendChild(row[c]);
            }

            tab.appendChild(tbo);            
            document.getElementById('mytable').appendChild(tab);
            mytable.setAttribute("align", "top-left");           

        }
        makeTable();

在此功能中,我想在警报中一次显示一个“tr”

    function GetCellValues()
    {
        var rows = document.getElementsByTagName('tr');
        for(var c = 0 ; c < rows.length ; c++)
        {   
          var row = rows[c];
          var inputs = row.getElementsByTagName('input');
// Here I want some code to retrieve "tr" value in a single single alert message Here I want each row data in one alert message...
        for(var k = 0 ; k < inputs.length ; k++)
            {           

// 意味着这里我想要 20 条警报消息,因为这里我们有 20 行...

                alert(inputs[k].value);  

 //I want to show the one "tr" at a time in  alert

            }
        }
    }
    window.onload = function()
    {
        makeTable();
    };
    </script>
</body>
</html>
4

2 回答 2

0

我不明白你的意思,但也许这会有所帮助。

function GetCellValues() {
var rows = document.getElementsByTagName('tr');
for (var c = 0; c < rows.length; c++) {
    var row = rows[c];
    var inputs = row.getElementsByTagName('input');

    // Here I want some code to retrieve "tr" value in a single alert message
    alert(rows[c].innerHTML);
}}
于 2013-11-07T05:47:05.477 回答
0
function GetCellValues() {
            var rows = document.getElementsByTagName('tr');
            for (var c = 0 ; c < rows.length ; c++) {
                var row = rows[c];
                var inputs = row.getElementsByTagName('input');                

                // Here I want some code to retrieve "tr" value in a single alert message
                var str = '';
                for (var k = 0 ; k < inputs.length ; k++) {
                    str += inputs[k].value + '  ';

                    //I want to show the one "tr" at a time in  alert

                }
                alert(str);
            }
        }
于 2013-11-07T05:42:57.263 回答