According to the w3 XHTML specification, the label
attribute specifies a shorter label for the option. However (using the try-it tool with FF3.5), I ca开发者_高级运维n't see any effect. Hence my question: what does this attribute really do?
EDIT
It seems that it overrides the label used in the dropdown list. The contents of the option are (as far as I know) only used as the default for the value
. Does this (in IE7+) make the following two declarations equivalent?
<option label="Volvo">Volvo (Latin for 'I roll')</option>
and
<option label="Volvo" value="Volvo (Latin for 'I roll')">Whatever....</option>
Note: The label attribute is only supported by IE 7+. Try in IE and you will see the difference.
The label attribute defines a shorter version of the text which will appear for its option in the drop-down list of the select menu.
label is defined as an optional attribute of the option tag, meaning implementation of and support for the attribute is not required to be compliant with the W3C standard. More information can be found here about the option tag:
http://www.w3schools.com/tags/att_option_label.asp
And, here is the link to the W3C specification:
http://www.w3.org/TR/html4/interact/forms.html#edef-OPTION
(Edit):
@Martijn the only usefulness I see is that it allows the developer to define an option tag and the label sets the "viewable text", and close it shorthand, rather than having to also specify a separate closing option tag. This would result in less code/data sent to the browser/device, which might have implications in mobile applications.
精彩评论