HTMLOptionsCollection: length 属性
HTMLOptionsCollection 接口的 length 属性返回集合中 <option> 元素的数量。该属性可以获取或设置集合的大小。
当将 length 设置为小于当前值时,选项集合会被截断;否则,新的空白 <option> 元素将被添加到 <select> 的末尾。
值
一个整数值,表示此 HTMLOptionsCollection 中项目的数量。
示例
js
const optCollection = document.getElementById("fruits").options;
const origLength = optCollection.length;
optCollection.length += 50; // adds 50 blank options to the collection
optCollection.length = origLength; // truncates the list back to the original size
规范
| 规范 |
|---|
| HTML # dom-htmloptionscollection-length-dev |
浏览器兼容性
加载中…