动态填充表的方法 [英] Method for Dynamically populating tables

查看:67
本文介绍了动态填充表的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个设计Intranet应用程序前端的团队。

后端人员将使用JSP和类似AJAX的功能来生成必须动态更改页面元素的
服务器请求。


创建和填充表格的最佳方法是什么,这些表格将存在于

浮动DIV中(具有拖放功能)?它只需要用IE6工作




我知道两种方式:


1.动态制作表格使用createElement(''< table>'')",

" insertRow()"等


2在hold DIV中使用innerHTML,在里面生成表格代码。


3.还有其他办法吗?


有什么优点和#1和#2的缺点?在速度方面(这些表中的一些是巨大的)? #2似乎更容易包围我,但是

可能效率不高?


感谢您的任何见解,

blueapricot416

I am on a team designing the front end of an Intranet application. The
backend guys will be using JSP and AJAX-like functionality to make
server requests that must dynamically change elements on a page.

What is the best way to create and populate tables, which will exist in
floating DIVs (with drag and drop capability)? It only has to work
with IE6.

I know of two ways:

1. Dynamically making the tables using "createElement(''<table>'')",
"insertRow()", etc.

2. Using innerHTML in the holding DIV, to generate table code inside.

3. Is there another way?

What are the pros and cons of #1 and #2? In terms of speed (some of
these tables are huge)? #2 seems easier to wrap my head around, but
maybe less efficient?

Thanks for any insights,
blueapricot416

推荐答案


bl ************ @ gmail.com 写道:
我知道两种方式:
1.动态制作表格使用createElement(''< table>'')",
" insertRow()"等

2.在hold DIV中使用innerHTML,在里面生成表格代码。
I know of two ways:
1. Dynamically making the tables using "createElement(''<table>'')",
"insertRow()", etc.

2. Using innerHTML in the holding DIV, to generate table code inside.




quirksmode.org有一篇关于这个主题的优秀文章,有性能

比较[1]


简短版本通常最快的方法是建立一个

数组的行,并将它们连接在一起并将其分配给innerHTML。

但我建议你阅读这篇文章。


Sam


[1] http://www.quirksmode.org/dom/innerhtml.html



quirksmode.org has an excellent article on the subject with performance
comparisons [1]

The short version is that generally the quickest way is to build up an
array of lines, and join them together and assign that to innerHTML.
But I recommend you read the article.

Sam

[1] http://www.quirksmode.org/dom/innerhtml.html

哇,好文章。谢谢你,Sam。


InnerHTML似乎是要走的路。也就是说,为什么Microsoft

建议你_NOT_使用innerHTML来生成表格?


具体来说:


注意当使用动态HTML(DHTML)创建文档时,您可以创建对象并设置

对象的innerText或innerHTML属性。但是,由于表所需的特定结构,表和tr对象的innerText和innerHTML属性是

只读。 (参见
http:// msdn.microsoft.com/workshop/a.../innerhtml.asp

了解更多信息。)


它说那里有innerHTML是只读的forTABLE,TBODY,TFOOT,

THEAD,TR" (除其他事项外)。然而,我可以使用innerHTML快速生成/写表

,创建< TABLEs>和< TRs>没有

故障的嘉豪?


为什么微软推荐_NOT_使用innerHTML生成

表,为什么他们说一些TABLE对象只有在他们可以写清楚的时候才会读取吗?


我有什么遗漏的吗?


谢谢,

blueapricot416

Wow, great article. Thank you, Sam.

InnerHTML seems to be the way to go. That said, why does Microsoft
recommend you do _NOT_ use innerHTML for generating tables?

Specifically:

"Note When using Dynamic HTML (DHTML) to create a document, you can
create objects and set the innerText or innerHTML property of the
object. However, because of the specific structure required by tables,
the innerText and innerHTML properties of the table and tr objects are
read-only." (See
http://msdn.microsoft.com/workshop/a.../innerhtml.asp
for more info.)

It says there that innerHTML is "readonly" for "TABLE, TBODY, TFOOT,
THEAD, and TR" (among other things). Yet, I can generate/write tables
rapidly using innerHTML, creating <TABLEs> and <TRs> galore without a
hitch?

Why does Microsoft recommend _NOT_ using innerHTML for generating
tables, and why do they say some TABLE objects are readonly when they
clearly can be written?

Is there something I am missing?

Thanks,
blueapricot416


bl ************ @ gmail.com 写道:
哇,很棒的文章。谢谢Sam。

InnerHTML似乎是要走的路。也就是说,微软为什么建议你_NOT_使用innerHTML来生成表格?
Wow, great article. Thank you, Sam.

InnerHTML seems to be the way to go. That said, why does Microsoft
recommend you do _NOT_ use innerHTML for generating tables?




我想它与IE如何解析HTML和将它转换为DOM - 但是

只是在猜测。事实上,修改表格的innerHTML

并不总是在IE中工作。

innerHTML是一项专有的Microsoft功能,已广泛使用复制在

其他浏览器中。它没有公布的标准和实现不同,

所以它并不总是可靠的。对于你来说,替换整个表格而不仅仅是行或单元格的内容可能更有效率,所以

innerHTML可能就好了。


[...]

-

Rob



I guess it''s to do with how IE parses HTML and converts it to a DOM - but
that''s just guessing. The fact is that modifying a table''s innerHTML
doesn''t always work in IE.

innerHTML is a proprietary Microsoft feature that has been widely copied in
other browsers. It has no published standard and implementations differ,
so it''s not always reliable. For you it may be more efficient to replace
an entire table rather than just the contents of a row or cell, so
innerHTML may well be the go.

[...]
--
Rob


这篇关于动态填充表的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆