开发者

What's the proper way to add selected and related attributes to inputs?

开发者 https://www.devze.com 2023-01-19 12:24 出处:网络
What is the proper way (standards compliant) way to add selected, disabled and similar attributes to <input> elements in HTML?

What is the proper way (standards compliant) way to add selected, disabled and similar attributes to <input> elements in HTML?

I have seen:

<input type="text" disabled>

<input type="text" disabled="disabled">

<input type="text" disabled="yes">

As far as I can tell, they all work, regardless of what the attribute's 开发者_如何转开发value is.

What is the right way to do this?


disabled is a boolean attribute.

disabled="disabled" is the correct form; disabled alone is shorthand allowed in HTML.

From On SGML and HTML:

Boolean attributes may legally take a single value: the name of the attribute itself (e.g., selected="selected").

In HTML, boolean attributes may appear in minimized form -- the attribute's value appears alone in the element's start tag. Thus, selected may be set by writing:

<OPTION selected>

instead of:

<OPTION selected="selected"> 

Authors should be aware that many user agents only recognize the minimized form of boolean attributes and not the full form.

0

精彩评论

暂无评论...
验证码 换一张
取 消