在HTML tag新增custom attribute
Can I add custom attribute to HTML tag?
http://stackoverflow.com/questions/1735230/can-i-add-custom-attribute-to-html-tag
這篇文章有2個解答, 擷取重點如下:
解答1:
--> You can add custom attributes to your elements at will. But that will make your document invalid.
--> In HTML 5 you will have the opportunity to use custom data attributes prefixed with data-.
e.g.
Something like this:
<tag data-myAttri="myVal" />
解答2:
You can amend your !DOCTYPE declaration (i.e. DTD) to allow it, so that the [XML] document will still be valid:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
[
<!ATTLIST tag myAttri CDATA #IMPLIED>
]>
#IMPLIED means it is an optional attribue, or you could use #REQUIRED, etc.
more info here:
http://www.w3schools.com/xml/xml_dtd_attributes.asp
http://stackoverflow.com/questions/1735230/can-i-add-custom-attribute-to-html-tag
這篇文章有2個解答, 擷取重點如下:
解答1:
--> You can add custom attributes to your elements at will. But that will make your document invalid.
--> In HTML 5 you will have the opportunity to use custom data attributes prefixed with data-.
e.g.
Something like this:
<tag data-myAttri="myVal" />
解答2:
You can amend your !DOCTYPE declaration (i.e. DTD) to allow it, so that the [XML] document will still be valid:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
[
<!ATTLIST tag myAttri CDATA #IMPLIED>
]>
#IMPLIED means it is an optional attribue, or you could use #REQUIRED, etc.
more info here:
http://www.w3schools.com/xml/xml_dtd_attributes.asp
留言
張貼留言