What is the fastest way to create a select tag with 5000 options in IE6?

大兔子大兔子 提交于 2019-12-01 14:58:07
Dr.Molle

Short test:

  • Collecting a innerHTML-string first and inject it to the document: around 300ms
  • appending options to an existing select-element using new Option(): around 25 sec
KooiInc

Appending options via DOM methods will cause a reflow/repaint of the screen for every option, slowing it all down. Using innerHTML after building a string (in memory) for your select is much faster (as Dr Molle told). An alternative to both methods would be to create an in memory documentFragment, build your select object in it and finally append it's contents into the exististing DOM.

This aside from the question how a user should handle 5000 options of course (alas, the user isn't programmable ;)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!