且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法使用按钮从动态生成的表中正确删除行

更新时间:2023-09-29 18:43:16

您可以使用 HTMLTableElement.insertRow() 函数。

You can use HTMLTableElement.insertRow() function instead.

var newRow = document.getElementById("table").insertRow();
// newRow.rowIndex will return you the proper index

这是一个工作小提琴

Here is a working fiddle

更新

这是Webkit布局引擎中的一个错误(也转移到了分叉的Blink引擎)。这就是为什么它在Firefox中运行良好但在早期版本的Chrome (Blink)或Safari(Webkit)中运行良好。

It was a bug in the Webkit layout engine, (that moved to the forked Blink engine as well). This is why it works well in Firefox but not in earlier versions of Chrome (Blink) or Safari (Webkit).

错误报告是此处,现已修复。

The bug report is here, it's fixed now.