JS高手进来看看,谁能完成这样一个动态的表格。
来源:百度知道 编辑:UC知道 时间:2024/05/21 07:05:51
我总觉得这就是个动态的2维数组而已......不知道我想对没有。
我写了个放在我的百度空间中,但是我的动态增加表格和你说的有点不一样,不过你可以去参考!
<script>
function MainRowInit()
{
var tabMain = document.getElementById("Main");
MainRow = tabMain.insertRow();
var MainRowCell = MainRow.insertCell();
var btnAddChild = document.createElement("input");
btnAddChild.type = "button";
btnAddChild.value = "增加子表一行";
btnAddChild.onclick = function()
{
ChildRowInit(this);
}
function ChildRowInit(aa)
{
var tab = aa.parentElement.parentElement.getElementsByTagName("table")[0];
var ChildRow = tab.insertRow();
var ChildRowCell = ChildRow.insertCell();
ChildRowCell.appendChild(document.createTextNode("这是个新子行"));
return ChildRow;
}
MainRowCell.appendChild(btnAddChild);
MainRowCell = MainRow.insertCell();
MainRowCell.appendChild(document.createElement("table"));
}
function