将行插入表中 [英] Insert rows into table
问题描述
在IE中将X行插入表格的最佳普通javascript方式是什么。
What is the best plain javascript way of inserting X rows into a table in IE.
表格html如下所示:
The table html looks like this:
<table><tbody id='tb'><tr><td>1</td><td>2</td></tr></tbody></table>
我需要做的是丢弃旧体,然后插入一个1000行的新体。我有1000行作为javascript字符串变量。
What I need to do, is drop the old body, and insert a new one with 1000 rows. I have my 1000 rows as a javascript string variable.
问题是IE中的表没有innerHTML函数。我见过很多黑客,但我希望看到你最好的。
The problem is that table in IE has no innerHTML function. I've seen lots of hacks to do it, but I want to see your best one.
注意:使用jquery或任何其他框架不计算在内。
Note: using jquery or any other framework does not count.
推荐答案
以下是实施IE的 innerHTML =
的文章在他如何让IE做 tbody.innerHTML = < tr> ...
:
Here's a great article by the guy who implemented IE's innerHTML=
on how he got IE to do tbody.innerHTML="<tr>..."
:
起初,我认为IE是不是
能够使用innerHTML执行
修改表的重绘,但是
然后我记得我是
负责此限制!
At first, I thought that IE was not capable of performing the redraw for modified tables with innerHTML, but then I remembered that I was responsible for this limitation!
顺便提一下,他使用的技巧基本上是所有框架为表
/ tbody
元素。
Incidentally the trick he uses is basically how all the frameworks do it for table
/tbody
elements.
编辑:@mkoryak,你的评论告诉我你没有想象力,也不值得回答。但无论如何我会幽默你。您的积分:
Edit: @mkoryak, your comment tells me you have zero imagination and don't deserve an answer. But I'll humor you anyway. Your points:
>他没有插入我需要的东西
> he is not inserting what i need
什么?他将行(他有一个html字符串)插入表
元素。
Wha? He is inserting rows (that he has as an html string) into a table
element.
>他还使用了一个额外的隐藏元素
> he also uses an extra hidden element
该元素的要点是说明所有IE需求都是上下文。您可以使用在运行中创建的元素( document.createElement('div')
)。
The point of that element was to illustrate that all IE needs is a "context". You could use an element created on the fly instead (document.createElement('div')
).
> ;而且这篇文章还很旧
> and also the article is old
我再也没有帮你;)
但是说真的,如果你想看看其他人是如何实现它的,看一下jQuery源代码 jQuery.clean()
,或Prototype的 Element._insertionTranslations
。
But seriously, if you want to see how others have implemented it, take a look at the jQuery source for jQuery.clean()
, or Prototype's Element._insertionTranslations
.
这篇关于将行插入表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!