Html 如何在多选中将“所有值”设置为默认值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20218417/
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
How to set "all values" as default in a multiple select?
提问by Pavel V.
There are questions on how to make one selection default, like this one. But I have a multiple select and want all the options to be selected initially. I found questions for something similar (like this), but not exactly what I want.
关于如何将一个选择设为默认值存在一些问题,比如这个。但是我有一个多选并希望最初选择所有选项。我发现了一些类似的问题(像这样),但不完全是我想要的。
Is this possible without JavaScript?
如果没有 JavaScript,这可能吗?
采纳答案by qiu-deqing
http://jsfiddle.net/UgHT5/is this your need?
http://jsfiddle.net/UgHT5/这是您的需要吗?
<select multiple>
<option selected>a</option>
<option selected>b</option>
<option selected>c</option>
</select>
回答by Pavel V.
It's much easier than I expected:
这比我预期的要容易得多:
<select multiple name="type">
<option selected value="1">type 1</option>
<option selected value="2">type 2</option>
<option selected value="3">type 3</option>
</select>
To find this referencewas enough.
找到这个参考就足够了。