var table = document.getElementById("tab"); var row = table.insertRow(0); // 在表格最后插入一行

                    if (data[i].subject_stype === "单选") {
                        var aa = row.insertCell(0);
                        aa.innerHTML = '<div style="display: block;" >【<input type="text" id="th" style="border: none;width: 50px; color: #00a2d4; white-space: nowrap; "disabled="disabled">】' +
                            '<input type="text" id="tmmc" style="border: none; width: 500px " disabled="disabled"></div><br>';

                        var radio = row.insertCell(1);
                        radio.innerHTML = '<input type="radio" name="ra"><input type="text" disabled="disabled" >' +
                            '<br><input type="radio" name="ra"><input type="text" disabled="disabled" > <br><br> ';
                    } else {
                        var aa = row.insertCell(0);
                        aa.innerHTML = '<div style="display: block;" >【<input type="text" id="th" style="border: none;width: 50px; color: #00a2d4; white-space: nowrap;" disabled="disabled">】' +
                            '<input type="text" id="tmmc" style="border: none; width: 500px " disabled="disabled"></div><br>';

                        var checkbox = row.insertCell(1);
                        checkbox.innerHTML = '<input type="checkbox" name="ch"><input type="text" disabled="disabled" >' +
                            '<br><input type="checkbox" name="ch"><input type="text" disabled="disabled" > <br><br> ';
                    }如何把添加的新行不在同一行显示内容:要使添加的新行不在同一行显示,可以通过修改代码中的insertRow()方法的参数来实现。将参数设置为已有行的数量,即可在表格中插入新的行:
var row = table.insertRow(table.rows.length);

这样新的行就会在表格中的最后一行显示,而不是在同一行。

JavaScript 表格添加新行,实现不同内容不在同一行显示

原文地址: https://www.cveoy.top/t/topic/pZhL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录