【发布时间】:2016-10-29 04:43:51
【问题描述】:
我创建一个 HTML 表格并在按钮事件上添加行和列。 这是我的代码:
function AddColumnToDataTable(){
$('#tableHeader').append("<th> Header </th>").attr("contenteditable", true);
// Add a new ColumnHeader and set the property "editable"
}
function AddRowToDataTable(){
var count = $('#tableHeader').find("th").length;
// Get the count of Columns in the table
var newRow = $('#tableBody').append("<tr></tr>");
// Add a new Row
for(var i = 0; i < count ; i++){
newRow.find('tr').last().append("<td> Content </td>").attr("contenteditable", true);
// Fill the cells with a default text and set the property "editable"
}
}
所以我想在添加新列时在旧行中设置新单元格。使行自动填充默认文本。
我必须计算索引吗? 我有 x 列,在第 y 行中设置了 z 单元格,填充缺少的单元格.. ?
【问题讨论】:
-
对不起,我无法理解这个问题。我看到您在标题中附加了新列,但不在行中。也许是这样?
标签: javascript jquery