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 |
瀏覽器相容性
載入中…