Should images have a "name" attribute?
I notice Dreamweaver creates a name
attribute automatically with the same value as id
, which I wouldn't have thought to do. I read t开发者_如何转开发his question asking the difference between name
and id
attributes in HTML, but what about where it applies to images?
Expando attributes won't hurt anything in any modern browser. It was officially supported in HTML 4.01, but removed in Strict XHTML:
http://www.w3.org/TR/xhtml1/
Regardless, it is pretty much useless for anything. Dreamweaver has included it for as long as I can remember.
A validator will complain (legitimately so) if you add an unsupported attribute to a tag.
name
is an attribute included for scripting backwards compatibility and should be of no use today.
http://www.w3.org/TR/html401/struct/objects.html#edef-IMG
name = cdata [CI]
This attribute names the element so that it may be referred to from style sheets or scripts. Note: This attribute has been included for backwards compatibility. Applications should use theid
attribute to identify elements.
Name is pretty much only useful for forms. You can use it as a way to add metadata to images, but there are more standard ways to do that these days.
ID attribute should be used for now.
The NAME attribute, added to IMG in HTML 4.01, specifies a name for referring to the image from a client-side script. The ID attribute provides the same functionality, but old browsers such as Netscape 4.x only support the NAME attribute.
Source: http://htmlhelp.com/reference/html40/special/img.html
精彩评论