加速document.getElementById()? [英] Speed Up document.getElementById()?
问题描述
您好,
我的AJAX应用程序将数据绘制到大约500个单元格中,每10秒钟具有唯一ID
。我正在使用document.getElementById()来查找
右侧单元格。但是,我注意到
IE中的document.getElementById()冻结了浏览器大约1秒钟,与Firefox不同。
任何人都可以建议任何速度改进以便将数据绘制到一个
大量的单元来加快这个过程?
你试过创建一个javascript吗?你创建的所有单元格的数组(或创建之后:取决于它们是否动态创建
或不是)文档元素?然后你可以引用数组的'
映射ID,而不是IE每次都找到文档元素。我不确定这是否会更快,但似乎会更快。
(启动时间稍长,但一旦装满所有内容就会更快) )
例如,在开头:
var arr = new Array(500);
for (x in arr)
{
arr [x] = document.getElementById(''cell''+ x);
}
然后,在整个文档的其余部分中,只需使用arr [ID]即可。
指向你想要操纵的文档元素。
4月30日上午9:36,vunet ... @ gmail.com写道:
你好,
我的AJAX应用程序将数据绘制到大约500个单元格中,每10秒就有一个唯一的ID
。我正在使用document.getElementById()来查找
右侧单元格。但是,我注意到
IE中的document.getElementById()冻结了浏览器大约1秒钟,与Firefox不同。
任何人都可以建议任何速度改进以便将数据绘制到一个
大量的细胞来加速这个过程?
4月30日上午10点15分,Derek< derek.detwei ... @ gmail.comwrote:
您是否尝试创建所有单元格的javascript数组,因为您创建了(或创建后:取决于它们是否动态创建
或不是)文件要素?然后你可以引用数组的'
映射ID,而不是IE每次都找到文档元素。我不确定这是否会更快,但似乎会更快。
(启动时间稍长,但一旦装满所有内容就会更快) )
例如,在开头:
var arr = new Array(500);
for (x in arr)
{
arr [x] = document.getElementById(''cell''+ x);
}
然后,在文档的其余部分中,只需使用arr [ID]即可。
指向你想要操纵的文档元素。
4月30日上午9:36,vunet ... @ gmail.com写道:
您好,
我的AJAX应用程序将数据绘制到大约500个单元格中,每10秒就有一个唯一ID
。我正在使用document.getElementById()来查找
右侧单元格。但是,我注意到
IE中的document.getElementById()冻结了浏览器大约1秒钟,与Firefox不同。
任何人都可以建议任何速度改进以便将数据绘制到一个
大量的细胞来加速这个过程?
我将测试您的解决方案并发布结果,谢谢。
< blockquote> 4月30日上午10点15分,Derek< derek.detwei ... @ gmail.comwrote:
您是否尝试过创建所有javascript数组你创建的单元格(或创建之后:取决于它们是否动态创建
或不是)文档元素?然后你可以引用数组的'
映射ID,而不是IE每次都找到文档元素。我不确定这是否会更快,但似乎会更快。
(启动时间稍长,但一旦装满所有内容就会更快) )
例如,在开头:
var arr = new Array(500);
for (x in arr)
{
arr [x] = document.getElementById(''cell''+ x);
}
然后,在文档的其余部分中,只需使用arr [ID]即可。
指向你想要操纵的文档元素。
4月30日上午9:36,vunet ... @ gmail.com写道:
您好,
我的AJAX应用程序将数据绘制到大约500个单元格中,每10秒就有一个唯一ID
。我正在使用document.getElementById()来查找
右侧单元格。但是,我注意到
IE中的document.getElementById()冻结了浏览器大约1秒钟,与Firefox不同。
任何人都可以建议任何速度改进以便将数据绘制到一个
大量的细胞来加速这个过程?
更新单元格的内容时,这是一项重大改进,但是我在构建此数组时损失了
。我的单元格是动态绘制的。
所以,直到我绘制整个表格,我都无法创建一个参考数组。
但是,当有这个数组时,我会重新绘制单元格内容比使用document.getElementById()更快
(减少80%)。
谢谢。
PS:任何提高速度的建议创建一个参考
数组? :)
Hello,
My AJAX application paints data into about 500 cells with unique ID
every 10 seconds. I am using document.getElementById() to find the
right cell. However, I have noticed that document.getElementById() in
IE is freezing the browser for about 1 second unlike Firefox.
Can anyone suggest any speed improvements for painting data into a
large number of cells to speed up the process?
Have you tried creating a javascript array of all of the cells as you
create (or after you create: depending if they''re dynamically created
or not) the document elements? Then you can just reference the array''s
mapped ID instead of IE finding the document element every time. I
don''t know for sure if this would be faster, but it seems it would be.
(slightly longer start-up, but faster once everything is loaded)
For example, at the beginning:
var arr = new Array(500);
for (x in arr)
{
arr[x] = document.getElementById(''cell'' + x);
}
Then, throughout the rest of your document, simply use "arr[ID]" to
point to the document element you are wanting to manipulate.
On Apr 30, 9:36 am, vunet...@gmail.com wrote:Hello,
My AJAX application paints data into about 500 cells with unique ID
every 10 seconds. I am using document.getElementById() to find the
right cell. However, I have noticed that document.getElementById() in
IE is freezing the browser for about 1 second unlike Firefox.
Can anyone suggest any speed improvements for painting data into a
large number of cells to speed up the process?
On Apr 30, 10:15 am, Derek <derek.detwei...@gmail.comwrote:Have you tried creating a javascript array of all of the cells as you
create (or after you create: depending if they''re dynamically created
or not) the document elements? Then you can just reference the array''s
mapped ID instead of IE finding the document element every time. I
don''t know for sure if this would be faster, but it seems it would be.
(slightly longer start-up, but faster once everything is loaded)
For example, at the beginning:
var arr = new Array(500);
for (x in arr)
{
arr[x] = document.getElementById(''cell'' + x);
}
Then, throughout the rest of your document, simply use "arr[ID]" to
point to the document element you are wanting to manipulate.
On Apr 30, 9:36 am, vunet...@gmail.com wrote:
Hello,
My AJAX application paints data into about 500 cells with unique ID
every 10 seconds. I am using document.getElementById() to find the
right cell. However, I have noticed that document.getElementById() in
IE is freezing the browser for about 1 second unlike Firefox.
Can anyone suggest any speed improvements for painting data into a
large number of cells to speed up the process?
I will test your solution and post the results, thank you.
On Apr 30, 10:15 am, Derek <derek.detwei...@gmail.comwrote:Have you tried creating a javascript array of all of the cells as you
create (or after you create: depending if they''re dynamically created
or not) the document elements? Then you can just reference the array''s
mapped ID instead of IE finding the document element every time. I
don''t know for sure if this would be faster, but it seems it would be.
(slightly longer start-up, but faster once everything is loaded)
For example, at the beginning:
var arr = new Array(500);
for (x in arr)
{
arr[x] = document.getElementById(''cell'' + x);
}
Then, throughout the rest of your document, simply use "arr[ID]" to
point to the document element you are wanting to manipulate.
On Apr 30, 9:36 am, vunet...@gmail.com wrote:
Hello,
My AJAX application paints data into about 500 cells with unique ID
every 10 seconds. I am using document.getElementById() to find the
right cell. However, I have noticed that document.getElementById() in
IE is freezing the browser for about 1 second unlike Firefox.
Can anyone suggest any speed improvements for painting data into a
large number of cells to speed up the process?
It is a significant improvement when updating cells'' content but I
lose time when building this array. My cells are drawn dynamically.
So, until I draw the whole table, I cannot create a reference array.
However, when having this array, I repaint cell content much faster
(by 80%) than if using document.getElementById().
Thank you.
PS: any suggestions for speed improvements to create a reference
array? :)
这篇关于加速document.getElementById()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!