css - html multi select option how to mark selected options? -
i using normal select , mutliselect boxes on site. should use <option selected="selected"> or <option selected> selected items ?
html5 spec:
https://www.w3.org/tr/html5/forms.html#attr-option-selected
the selected attribute boolean attribute.
http://www.w3.org/tr/html5/infrastructure.html#boolean-attributes :
the presence of boolean attribute on element represents true value, , absence of attribute represents false value.
if attribute present, value must either empty string or value ascii case-insensitive match attribute's canonical name, no leading or trailing whitespace.
conclusion:
the following valid, equivalent , true:
<option selected /> <option selected="" /> <option selected="selected" /> <option selected="selected" /> the following invalid:
<option selected="0" /> <option selected="1" /> <option selected="false" /> <option selected="true" /> the absence of attribute valid syntax false:
<option /> recommendation
if care writing valid xhtml, use selected="selected", since <option selected> invalid xhtml (but valid html) , other alternatives less readable. else, use <option selected> shorter.
Comments
Post a Comment