如何按行和列索引设置单元格的值
How to set value of a cell by row and column index?
我有这个到目前为止,但它不会改变单元格值:
function setCellValue(tableId, rowId, colNum, newValue)
{
$('#'+tableId).find('tr#'+rowId).find('td:eq(colNum)').html(newValue);
};
通过连接索引创建选择器( :eq()
索引从0
开始)。虽然您需要对行选择器进行相同的操作,因为rowId
是tr
的索引,而不是id
。
function setCellValue(tableId, rowId, colNum, newValue)
{
$('#'+tableId).find('tr:eq(' + (rowId - 1) + ')').find('td:eq(' + (colNum - 1) + ')').html(newValue);
};
或者使用 :nth-child()
伪类选择器
function setCellValue(tableId, rowId, colNum, newValue)
{
$('#'+tableId).find('tr:nth-child(' + rowId + ')').find('td:nth-child(' + colNum + ')').html(newValue);
};
或通过避免 find()
方法使用单个选择器。
function setCellValue(tableId, rowId, colNum, newValue)
{
$('#' + tableId + ' tr:nth-child(' + rowId + ') td:nth-child(' + colNum + ')').html(newValue);
// or
$('#' + tableId + ' tr:eq(' + (rowId - 1) + ') td:eq(' + (colNum - 1) + ')').html(newValue);
};
相关文章:
- 如何将css类设置为表头单元格
- 为什么谷歌应用程序的电子表格setValue函数没有在单元格中设置值
- Google Sheets / Javascript -> 遍历数组并将值设置为单元格
- Google Apps 脚本,用于根据一个单元格的值对另一个单元格进行条件颜色格式设置
- jqgrid在条件下动态设置单元格可编辑false
- 使用jQuery在表格单元格中设置链接
- 如何在后台网格中将特定的可编辑单元格设置为不可编辑
- 根据条件设置单元格值
- 设置单元格值,使其在内联编辑中保持可编辑状态
- 将显示:无设置为第一行的单元格会弄乱表格布局
- 数据表:如何将类设置为表行单元格(但不是表标题单元格!
- 谷歌地理图表点击设置单元格不起作用
- 在表格单元格上设置鼠标悬停
- 在 ExtJS 4 网格中设置单元格 ID
- 如何在网格数据绑定为动态时为 jqgrid 单元格设置自定义标题
- 如何在jQuery中使用handontable为特定单元格设置属性
- jQuery fullCalendar为单元格设置背景色
- 在谷歌电子表格中,如何从另一个单元格设置单元格的值's值
- 可手持-can't为自定义单元格设置千分隔符
- 如何在编辑行时自动将Google Sheets单元格设置为当前日期