//自动补全空白列 var rows = document.getElementById("gridTable").rows; //行对象 var allcells = rows[1].cells.length; //第二行所有列数做为初始数据,即最大列数 for (var i = 2; i < rows.length; i++) { var num = allcells - rows[i].cells.length; for (var k = 0; k < num; k++) { cell = rows[i].insertCell(); cell.innerHTML = "0"; } }