如何在HTML中的选择(下拉)菜单中设置不可选择的默认描述? [英] How do I set an un-selectable default description in a select (drop-down) menu in HTML?

查看:102
本文介绍了如何在HTML中的选择(下拉)菜单中设置不可选择的默认描述?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户选择语言的下拉菜单:

I have a drop down where the user selects a language:

<select>
    <option>English</option>
    <option>Spanish</option>
</select>




  1. 我想要初始显示的默认选项为Select
    a语言而不是英语(我的第一个选项,默认显示为
    )。
  2. 我不希望用户能够选择选择一个语言。


推荐答案

如果select中的选项都没有 selected 属性,第一个选项将是选中的选项。

If none of the options in the select have a selected attribute, the first option will be the one selected.

为了选择不是第一个的默认选项,添加选定的属性:

In order to select a default option that is not the first, add a selected attribute to that option:

<option selected="selected">Select a language</option>

您可以阅读 HTML 4.01规范,关于select元素中的默认值。

You can read the HTML 4.01 spec regarding defaults in select element.

我建议阅读一本好的HTML书如果您需要学习像这样的HTML基础知识 - 我推荐 Head First HTML

I suggest reading a good HTML book if you need to learn HTML basics like this - I recommend Head First HTML.

这篇关于如何在HTML中的选择(下拉)菜单中设置不可选择的默认描述?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆