Select size attribute
Definition and Usage
size
Attribute to set or return the size of the dropdown list Size attribute Value.
The size attribute specifies the number of visible options in the dropdown list.
Note:In Chrome and Safari, the size attribute may not work properly for size="2" and size="3".
See also:
HTML Reference Manual:HTML <select> size 属性
HTML Reference Manual:HTML <select> 标签
Example
Example 1
Change the number of visible options in the dropdown list:
document.getElementById("mySelect").size = "4";
Example 2
Return the number of visible options in the dropdown list:
var x = document.getElementById("mySelect").size;
Syntax
Return size attribute:
selectObject.size
Set size attribute:
selectObject.size = number
属性值
值 | 描述 |
---|---|
number |
规定下拉列表中可见选项的数量。 如果该值大于 1,但小于列表中的选项总数,浏览器会添加滚动条,表示还有更多选项可以查看。 |
技术细节
返回值: | 数值,表示下拉列表中可见选项的数量。 |
---|
浏览器支持
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
支持 | 支持 | 支持 | 支持 | 支持 |