I was reading up about DOM and I saw this function DOMCharacterD开发者_高级运维ata::appendData
. It appends the string data to the character data. So in layman's terms, what is character data?
It is defined in non layman's terms in the standard here.
But more simply, character data is any text in the HTML, that isn't part of a tag. This is in contrast to tags, attributes etc. It can be just typed as text, or defined with a CDATA section in the html, or a comment etc.
Example html:
<tag attribute="value">This is character data</tag>
<a><![CDATA[This is also all character data]]></a>
<!-- even this comment is character data -->
In the code above "This is all character data" is character data, but the tag surrounding it isn't. The same goes for the CDATA section and the comment. One thing that often surprises people is that whitespace counts as character data.
Character data is plain, simple text. Things such as DOMText
and DOMComment
inherit from DOMCharacterData
because they contain text data.
精彩评论