HTML 下拉控件中是否有最大数量的选项(值)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42763/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a max number of options (values) in HTML drop down control?
提问by Steve Tranby
Does anyone know how many options a drop down list can have? Is it unlimited? How many before performance degrades?
有谁知道下拉列表可以有多少个选项?是无限的吗?在性能下降之前有多少?
采纳答案by Jason Bunting
Does anyone know how many options a drop down list can have? Is it unlimited?
有谁知道下拉列表可以有多少个选项?是无限的吗?
I imagine it is unlimited in theory, obviously not in practice as a computer's RAM and the specific browser's limitations come into play.
我想它理论上是无限的,显然在实践中不是,因为计算机的 RAM 和特定浏览器的限制开始发挥作用。
How many before performance degrades?
在性能下降之前有多少?
Again, this would depend on a few factors, at the least the specific browser, the computer's memory and processing power.
同样,这取决于几个因素,至少取决于特定的浏览器、计算机的内存和处理能力。
EDIT: From experience, I have had drop down lists with thousands of options. It wasn't ideal though because who wants to scroll through all of those? This is why an auto-complete of some type is more desirable for numerous reasons, especially the end user's experience.
编辑:根据经验,我有包含数千个选项的下拉列表。但这并不理想,因为谁想滚动浏览所有这些?这就是为什么出于多种原因,尤其是最终用户的体验,某种类型的自动完成更受欢迎。
回答by Katesclau
Update: Based on DannyG, tested on Ubuntu with Firefox on a 4GB mem pc, limit was far beyond 10k tags. My current Firefox is set to use up to 3GB and it has reached a 100k options, but for that, you'd have to change the default config of the browser I guess.
更新:基于 DannyG,在 Ubuntu 和 Firefox 的 4GB mem pc 上测试,限制远远超过 10k 标签。我当前的 Firefox 设置为最多使用 3GB,它已达到 100k 选项,但为此,我猜您必须更改浏览器的默认配置。
We opted to use an Ajax autocomplete as replacement in all cases that 30+ options where given.
在给出 30 多个选项的所有情况下,我们选择使用 Ajax 自动完成作为替代。
Both Firefox and Chrome limited to 10k options in Windows 64b with 4GB ram on default config.
Firefox 和 Chrome 在 Windows 64b 中限制为 10k 选项,默认配置为 4GB 内存。
Tested with JSFiddle http://jsfiddle.net/Mare6/
使用 JSFiddle http://jsfiddle.net/Mare6/ 进行测试
Html:
网址:
<a>Testing Select</a>
<select id="list"></select>
Javascript
Javascript
window.onLoad = function() {
for (var i=0; i<10000; i++) {
var name = "Option "+i;
var sel = document.getElementById("list");
sel.options[sel.options.length] = new Option(name,i);
}
});
Regards,
问候,
回答by Ethan Gunderson
I've used right around 500 in a list with no noticeable performance impact if that helps!
如果有帮助,我已经在列表中使用了大约 500 个,没有明显的性能影响!
回答by Kevin London
Yes, the maximum for Chrome and Safari is 10000 items for select
elements at least.
是的,Chrome 和 Safari 的最大select
元素至少为 10000 个项目。
The relevant lines in the Chrome source can be found here: Defined max of 10000, Code that enforces limit and puts error in console
可以在此处找到 Chrome 源中的相关行: Defined max of 10000,强制限制并将错误放入控制台的代码
Firefox seems to have no practical limit from my testing.
从我的测试来看,Firefox 似乎没有实际限制。
回答by stjohnroe
In my experience the performance degradation is generally on the side of the user, my golden rule (learned somewhere) is seven options, give or take a few.
根据我的经验,性能下降通常是在用户方面,我的黄金法则(从某处学到)是七个选项,给或取几个。
On a more SW related basis, probably the top range of Integer.
在更多与 SW 相关的基础上,可能是 Integer 的最高范围。
EDIT: BTW This is kind of relevant from Atwood
编辑:顺便说一句,这与阿特伍德有关
回答by Ben
In theory, there is no limit, but some browsers will implement limits. (Similar to using document.write
in an infinite loop.)
理论上没有限制,但有些浏览器会实施限制。(类似于document.write
在无限循环中使用。)
But, at the end of the day, the most I would ever recommend in a drop-down-list, is about 50, just because no-one wants to do that much scrolling. That said, if organized, say by alphabetical order, it may be appropriate to have as many as 200 items in a drop-down-list. (Like for a sign-up form where you must select you country of birth.)
但是,归根结底,我在下拉列表中推荐的最多是大约 50 个,只是因为没有人想要做那么多滚动。也就是说,如果按字母顺序组织,在下拉列表中包含多达 200 个项目可能是合适的。(例如必须选择出生国家/地区的注册表单。)
Also, when you have many different set choices, a drop-down-list is normally the best option, regardless.
此外,当您有许多不同的设置选择时,无论如何,下拉列表通常是最佳选择。