在用户选择语言的地方,我有一个下拉列表:
<select>
<option>English</option>
<option>Spanish</option>
</select>
发布于 2011-03-06 19:50:09
如果select中没有一个选项具有selected
属性,则第一个选项将是选中的选项。
为了选择一个不是第一个的默认选项,向该选项添加一个selected
属性:
<option selected="selected">Select a language</option>
您可以在select元素中读取有关默认值的HTML4.01规范。
如果你需要像这样学习HTML基础知识,我建议阅读一本好的HTML书籍--我推荐头第一HTML。
发布于 2013-05-13 14:51:23
在Oded的答案的基础上,您也可以设置默认选项,但如果它只是虚拟文本,则不能将其设置为可选择的选项。例如,您可以:
<option selected="selected" disabled="disabled">Select a language</option>
这将在用户单击复选框之前显示“”,但由于禁用的属性,用户将无法选择它。
发布于 2015-07-10 03:36:57
.selectmenu{
-webkit-appearance: none; /*Removes default chrome and safari style*/
-moz-appearance: none; /* Removes Default Firefox style*/
background: #0088cc ;
width: 200px; /*Width of select dropdown to give space for arrow image*/
text-indent: 0.01px; /* Removes default arrow from firefox*/
text-overflow: ""; /*Removes default arrow from firefox*/ /*My custom style for fonts*/
color: #FFF;
border-radius: 2px;
padding: 5px;
border:0 !important;
box-shadow: inset 0 0 5px rgba(000,000,000, 0.5);
}
.hideoption { display:none; visibility:hidden; height:0; font-size:0; }
Try this html
<select class="selectmenu">
<option selected disabled class="hideoption">Select language</option>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
<option>Option 4</option>
<option>Option 5</option>
</select>
https://stackoverflow.com/questions/5212939
复制相似问题