开发者

Fastest Way to Add a Column to an HTML Table

I want to dynamically add some columns (and remove others) from an html table. As there is no html <tr> analog for columns, the best way I can think of is to loop over the rows and add <td>'s with javascript. This is slow though as it causes a lot of browser reflows (I have a lot of rows to modify), and I am wondering if any javascript/css wizards know a trick to ma开发者_开发技巧ke this faster.


You can create a brand new table DOM element and copy the existing table's children to it, adding your new <td>s in the right places, then, when you are all done constructing the DOM tree for the new table, remove the old table and put the new one in place. This will cause only one reflow.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜