javascript HTML 选择框显示为多个,但要禁用多选?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14155752/
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
HTML Select Box show as Multiple, but to Disable Multiple Selection?
提问by u775856
I needed to have:
我需要:
- A html
<select>
box showing as a vertically expanded box (not a Dropdown). So i set it asmultiple
.
- 一个 html
<select>
框,显示为一个垂直展开的框(不是下拉框)。所以我把它设置为multiple
.
Then it is showing correctly as:
然后它正确显示为:
<select id="gagaga" multiple>
<option>A</option>
<option>B</option>
<option>C</option>
</select>
- Then how can i make it non-multiple selectable? (to
allow only 1 selection
)
- 那么我怎样才能使它不可多选呢?(对
allow only 1 selection
)
回答by ameya rote
Use this size="3"
用这个 size="3"
<!DOCTYPE html>
<html>
<body>
<select id="gagaga" size="3">
<option>A</option>
<option>B</option>
<option>C</option>
</select>
</body>
</html>
If the value of the size attribute is greater than 1, but lower than the total number of options in the list, the browser will add a scroll bar to indicate that there are more options to view.
如果size属性的值大于1,但小于列表中的选项总数,浏览器会添加一个滚动条,表示有更多的选项可以查看。
回答by adi rohan
Do not use the multiple attribute instead set the size for it .
不要使用 multiple 属性,而是为其设置大小。
Quoted from w3schools:
引自 w3schools:
The size attribute specifies the number of visible options in a drop-down list.
If the value of the size attribute is greater than 1, but lower than the total number of options in the list, the browser will add a scroll bar to indicate that there are more options to view.
size 属性指定下拉列表中可见选项的数量。
如果size属性的值大于1,但小于列表中的选项总数,浏览器会添加一个滚动条,表示有更多的选项可以查看。
回答by Avio
You can use this:
你可以使用这个:
<html>
<body>
<select id="gagaga" size="3">
<option>A</option>
<option>B</option>
<option>C</option>
</select>
</body>
</html>
回答by Jai
you need to provide size
to it:
你需要提供size
给它:
<select id="gagaga" size='3'>
<option>A</option>
<option>B</option>
<option>C</option>
</select>
and just remove the multiple
there, It will enable you to select just one option in the list.
并删除multiple
那里的,它将使您能够仅选择列表中的一个选项。