【发布时间】:2013-10-18 13:32:19
【问题描述】:
对于选择元素,length 属性和options.length 属性有什么区别吗?
特别是,我很想知道在浏览器支持方面是否存在差异。
【问题讨论】:
-
你能澄清“差异”吗?输出不同,执行速度不同..?
-
@RUJordan 有什么不同。到目前为止我还没有找到,我想知道为什么我们需要两个行为相同的属性。
-
你应该使用
.options.length,它的意图清晰,更干净。 The.lengthproperty on the<select>itself does only exist because it can act as the options container itself (quirks introduced by IE and standardized with HTML5). -
@Bergi 不是根据developer.mozilla.org/en-US/docs/Web/API/…,它声明 select.length 正式表示“此选择元素中
-
@Christophe:我不知道(也不会在意)。每个当前的、体面的浏览器都支持这两者;可能是早期的 IE/NN 不支持
.options.length,早期的其他浏览器不兼容 IE。
标签: javascript forms dom select