向表中添加新列时,用默认单元格填充当前行
Fill current rows with default cells when adding new columns to the table
我创建了一个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个单元格,填充缺失的。div ?
如果我正确理解了这个问题,您需要在当前行中添加新列也对吗?
然后像这样的东西应该做的技巧(如果我没有理解正确,请评论,以便我可以删除或更新我的答案):
function AddColumnToDataTable() {
$('#tableHeader').append("<th>Header</th>").attr("contenteditable", true); // Add a new ColumnHeader and set the property "editable"
$('#tableBody').find("tr").each(function() {
$(this).append('<td>Content</td>');
});
}
function AddRowToDataTable(){
var count = $('#tableHeader').find("th").length;
// Get the count of Columns in the table
var newRow = $('#tableBody').append("<tr></tr>");
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"
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr id="tableHeader"><th>Header</th></tr>
<tbody id="tableBody">
</tbody>
</table>
<input onclick="AddColumnToDataTable();" type="button" value="Column" />
<input onclick="AddRowToDataTable();" type="button" value="Row" />
相关文章:
- 使用jquery在单击时在单元格中输入值
- 谷歌应用程序-不;t在使用调试运行脚本期间填充电子表格单元格
- 从已填充的单元格中获取总列
- 如何用背景色动态填充表格单元格
- 在二维网格中随机填充固定数量的单元格
- 填充在“;显示:表格单元格”;
- 使用javascript创建10*10表,并使用从黑色到白色的颜色填充单元格
- 尝试使用javascript更改单元格填充
- 表格单元格中预填充的文本显示为“未定义”.当在JS中添加HTML标签时
- Google Scripts从单元格中填充值数组及其位置
- DHTMLX网格:用下拉菜单填充单元格
- 向表中添加新列时,用默认单元格填充当前行
- If语句表示单元格为n't时已被填充
- 如何在Javascript中垂直填充数据单元格
- 在Google工作表中编辑前一个单元格时自动填充日期
- EXTJS在Ext.property.Grid填充内容时为单元格上色
- 在选定表格行后,用表格单元格数据填充文本框
- 使用JQuery获取鼠标悬停时动态填充的表格单元格的背景颜色
- 如何填充单元格哪些单元格未在jqGrid中编辑
- 当下一行的单元格填充位置时,删除表单元格