HTML SELECT元素是否需要value属性? [英] Is a value attribute required for a HTML SELECT element?

查看:193
本文介绍了HTML SELECT元素是否需要value属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发布到服务器的选择菜单值应与OPTION元素中的文本相同.

The select menu value posted to the server should be the same as the text in the OPTION element.

在我使用的浏览器上,以下内容会产生相同的结果.

On the browser I am using, the following produce identical results.

第二个脚本是否正确"并支持跨浏览器?

Is the second script "correct" and cross browser supported?

 <select>
  <option value="AAA">AAA</option>
  <option value="BBB">BBB</option>
  <option value="CCC">CCC</option>
</select>

 <select>
  <option>AAA</option>
  <option>BBB</option>
  <option>CCC</option>
</select>

推荐答案

根据 MDN 该属性是可选的,因为如果省略该值,则从文本中推断出该值

According to MDN the attribute is optional as the value is inferred from the text if it is omitted

此属性的内容表示要提交的值 与表格一起使用时,应选择此选项.如果此属性是 省略,该值取自选项的文本内容 元素.

The content of this attribute represents the value to be submitted with the form, should this option be selected. If this attribute is omitted, the value is taken from the text content of the option element.

这篇关于HTML SELECT元素是否需要value属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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