html表单下拉菜单

Drop-down menus are used on forms to capture responses for which there is one correct response from multiple possible answers. A good example of this is asking for a visitor’s province, state or country.

表单上使用下拉菜单来捕获响应,对于这些响应,可以从多个可能的答案中获得一个正确的响应。 一个很好的例子就是要求访问者所在的省,州或国家。

考虑替代方案 (Considering Alternatives)

It's important to consider all the possibilities when making a form. We could simply present a textbox in which the user could type the province name, but that allows the possibility that they could make a typing mistake (which becomes an issue if this information is entered directly into a database, without human oversight). We could reduce the size of the textbox to to allow just two characters, and prompt the user just to type in the province or state abbreviation: while that reduces the possibility of error, it does not remove it.

制作表格时,必须考虑所有可能性。 我们可以简单地显示一个文本框,用户可以在其中输入省名,但是这允许他们可能会键入错误(如果将此信息直接输入到数据库中而没有人为监督,则会成为问题)。 我们可以将文本框的大小减小为仅允许两个字符,并提示用户仅输入省或州的缩写:虽然这会减少出错的可能性,但不会将其删除。

One of the best solutions to use for a question in a form for which there is only one right answer from a large number of possibilities is a drop-down menu.

下拉菜单是在多种可能性中只有一个正确答案的形式中用于问题的最佳解决方案之一。

下拉标记 (Drop-down Markup)

In an HTML form, this is created through the use of the <select> tag.

在HTML表单中,这是通过使用<select>标记创建的。

As always, we place our <label> in first, with a for attribute and an appropriate accesskey. Just like the <input> tag, <select> should have an id and name attribute. Each item inside the drop-down menu is then delimited by <option> tags.

与往常一样,我们将<label>放在第一位,带有for属性和适当的accesskey 。 就像<input>标记一样, <select>应该具有idname属性。 然后,下拉菜单中的每个项目都由<option>标记分隔。

<label for="province" accesskey="p">Province / Territory</label>
<select name="province" id="province"><option>Alberta<option>British Columbia
</select>

The form itself is not aware of any text between the opening and closing option tags. While the first option can be selected by our user, no actual data will be sent to the formhandler.php script which interprets the data in the form. We probably don’t want the word “Alberta” in any case; “AB” would be preferable for adding to a mailing list or database. To do this, we must add value attributes to each of these options:

表单本身不知道在开始和结束option标签之间的任何文本。 尽管我们的用户可以选择第一个选项,但不会将实际数据发送到formhandler.php脚本,该脚本会解释表单中的数据。 在任何情况下,我们可能都不希望使用“艾伯塔省”一词。 添加到邮件列表或数据库时,最好使用“ AB”。 为此,我们必须将value属性添加到以下每个选项中:

<select name="province"><option value="AB">Alberta<option value="BC">British Columbia
</select>

(Note that the value attribute can also be used to pre-set the text for an <input> textbox).

(请注意, value属性还可以用于为<input>文本框预先设置文本)。

Finally, the first option in our drop-drown menu will be auto-selected by default. This is not always a good thing. First, keep in mind our assumptions about our user. If we have pre-selected something, it is likely that he will skip over it to save time or simply miss it. It is better to prompt the user to make a selection and make that prompt selected by default, unless you can be absolutely certain that the vast majority of the respondents to your form will meet a pre-selected criteria.

最后,默认情况下将自动选择下拉菜单中的第一个选项。 这并不总是一件好事。 首先,请记住我们对用户的假设。 如果我们预先选择了某些内容,他可能会跳过它以节省时间或只是错过了它。 最好提示用户进行选择,并默认使该提示处于选中状态,除非您可以绝对确定表单的绝大多数答复者都将满足预选条件。

<select name="province"><option value="none" selected="selected"> -- choose one --<option value="AB">Alberta<option value="BC">British Columbia
</select>

You will find textbooks and online help that provide code to make multiple options in the drop-down list selectable, or which turns the select drop-down into a scrolling interface. Generally speaking, these practices are strongly inadvisable. People become confused when presented with them, leading to data entry errors.

您会找到教科书和在线帮助,这些教科书和在线帮助提供了使下拉列表中的多个选项变为可选的代码,或者将选择下拉列表变成了滚动界面。 一般来说,强烈建议不要使用这些做法。 人们在与他们在一起时会感到困惑,从而导致数据输入错误。

The optgroup element should be used to indicate groups of related options in a drop-down; the optgroup itself is not selectable. Rather confusingly, the optgroup has a required attribute, label, that is used to indicate the group reference.

optgroup元素应用于在下拉列表中指示相关选项的optgroup本身是不可选择的。 令人困惑的是, optgroup具有必需的属性label ,用于指示组引用。

For example, to show states in the US and provinces/territories in Canada in the same drop-down, we could do the following.

例如,要在同一下拉列表中显示美国各州和加拿大的省/地区,我们可以执行以下操作。

<label for="state" accesskey="s">State / Province / Territory</label>
<select name="state" id=state"><option value="">-- choose one --<optgroup label="USA"><option value="AL">Alabama<option value="CA">California<option> … remaining US states … </optgroup><optgroup label="Canada"><option value="AB">Alberta<option value="CA">British Columbia<option> … remaining provinces and territories … </optgroup>
</select>

In the browser, the result would look something like this:

在浏览器中,结果如下所示:

State / Province / Territory州/省/地区 -- choose one -- - 选一个 -

  • Alabama阿拉巴马州California加利福尼亚州 … remaining US states … …美国其余州… Alberta艾伯塔省British Columbia不列颠哥伦比亚省 … remaining provinces and territories … ……其余省份和领土……
  • For a select menu this long and complicated, it is usually a good idea to use JavaScript to dynamically alter the content of the select based on user choices earlier in the form. For example, having the user choose their country first should reduce the number of visible options in the “state” drop-down to show only the relevant territories in their particular nation. This makes for a more intelligent and intuitive form, and a better user experience.

    对于一个如此漫长而复杂的select菜单,通常最好使用JavaScript根据表单中较早的用户选择动态更改select内容。 例如,让用户首先选择他们的国家应该减少“州”下拉列表中可见选项的数量,以仅显示其特定国家/地区中的相关领土。 这使表格更智能,更直观,并提供了更好的用户体验。

    Naturally, a <select> menu is not only used for geographical location; there are many instances in which it can be used to capture single answers from multiple possibilities: sizes when shopping for T-shirts, for example.

    自然, <select>菜单不仅用于地理位置; 在很多情况下,它可以用来捕获多种可能性的单个答案:例如,购买T恤时的尺码。

    翻译自: https://thenewcode.com/166/HTML-Forms-Drop-down-Menus

    html表单下拉菜单

html表单下拉菜单_HTML表单:下拉菜单相关推荐

  1. htmla标签下划线去除_html超链接的下划线怎么去掉?a标签去下划线的方法都在这里...

    本篇文章就是关于html超链接取消下划线的用法,教你如何快速的去掉HTML超链接下划线的方法,最后还有相关代码解释,下面就让我们一起看看这篇文章吧 首先我们使用css的基础样式来做一个最简单的去下划线 ...

  2. htmla标签下划线去除_html超链接去掉下划线 html去除取消超链接下划线

    html a超链接标签,默认有的涉猎器表现有下划线,有的不有下划线,大多锚文本超链接A标签内字体是有下划线的,怎么去除超链接下划线?html 超链接去除下划线怎么样做? 去掉去除超链接锚文本的下划线需 ...

  3. 下拉菜单被表单、图片、FLASH挡住的解决办法

    设置Flash的参数: <param name="wmode" value="opaque"> <object classid="c ...

  4. WordPress程序有哪些下拉菜单样式表代码?

    WordPress主题最常用的菜单体验方式就是下拉菜单,但是很多新手对菜单的使用和调整方式都不是很明白,不懂样式表的更难操作. 那么WordPress程序有哪些下拉菜单样式表代码?今天就为大家提供现成 ...

  5. html表单按钮有,用好表单的按钮(一)_html

    对于一个交互式表单,按钮是必不可少的.按钮一般分为两类,一类本身就具有特定的功能,叫做特殊按钮,如Submit(提交按钮)――用于传输用户所填写的信息至服务器.Reset(复原按钮)――清除所填写的信 ...

  6. PHP PHPExcel 下拉 让其只能在其下拉的分表隐藏并设置解锁密码

    PHP PHPExcel 下拉 让其只能在其下拉的分表隐藏并设置解锁密码 $obpe->getActiveSheet()->setSheetState(\PHPExcel_Workshee ...

  7. MySQL将表中的yes改成no_mysql在不需要改程序的情况下通过操作数据库对单表数据量大的表进行分表...

    1.为什么要分表? 数据库数据越来越大,随之而来的是单个表中数据太多.以至于查询速度变慢,而且由于表的锁机制导致应用操作也搜到严重影响,出现了数据库性能瓶颈. mysql中有一种机制是表锁定和行锁定, ...

  8. ajax如何提交多表单的值_25 HTML5表单基本控件(二)

    成长是一辈子的事儿!大家好!我是时问新.分享前端.Python等技术,以及个人成长路上的那些事儿. 密码框 使用标签,把标签上的type属性的值,设置为"password",就可以 ...

  9. html书写表单laber,day02_HTML表格列表表单

    定义表格列的组. 1.4单元格合并 1. 确定目标单元格位置 目标单元格的位置,原则为上边的单元格优先级大于下边的单元格优先级,左边的单元格优先级大于右边的优先级. 2. 确定合并方式 根据合并方向, ...

最新文章

  1. 基于MATLAB的OSPF协议网络仿真
  2. 事件控制块的原理与创建
  3. 转发一份GoldenGate 配置文档,里面有参数说明,值得看
  4. Visual studio 2012 ultimate 安装遇到 Prerequisites , 错误的函数 incorrect function
  5. java项目如何更改路径_Java修改eclipse中web项目的server部署路径问题
  6. CCNA学习总结—OSPF协议—OSPF协议原理
  7. SAP License:你适合做SAP顾问吗?
  8. boxplot函数--Matplotlib
  9. 域名不要www如何解析
  10. HTML网页图像标签
  11. WPS Excel表格怎么启用宏功能?
  12. Redis之过期键删除策略
  13. android 开发英语单词统计
  14. python如何画散点图
  15. [xml]DOM4j解析
  16. HDU 5514 题解
  17. 计算机与机械工程相结合的专业,计算机和机械有何结合的专业
  18. linux gcc comand not,gcc: command not found
  19. 计算机硬件简笔画,电脑的鼠标上色简笔画图片教程步骤
  20. 《Java解惑》系列——02字符谜题——谜题17:嗯??

热门文章

  1. 怎么剪辑视频教程,剪辑视频的软件怎么剪辑视频制作原创视频
  2. HTML期末大作业 仿小米商城网页设计与制作(HTML+CSS+JavaScript) JavaScript期末大作业 web前端期末大作业 dw静态网页
  3. 【python】image库使用以及验证码识别
  4. 刚学平面设计如何用简单的方法来设计字体
  5. 游戏设计行业应该选哪一块去学习,然后就业?哪个前景更好
  6. C++内存越界问题请教
  7. 图卷积神经网络1-谱域图卷积:拉普拉斯变换到谱域图卷积
  8. 浅学Html5CSS
  9. mysql exists和in
  10. HTML中段落首字下沉的实现方法