. This writing method is also the so-called self-closing method, which is completely legal in XML. If you are familiar with XML-related development, you may be accustomed to this way of writing. Think of it as any element in XML that does not contain child nodes can be written in this way, so tags without content in XHTML can also be written in this way."/> . This writing method is also the so-called self-closing method, which is completely legal in XML. If you are familiar with XML-related development, you may be accustomed to this way of writing. Think of it as any element in XML that does not contain child nodes can be written in this way, so tags without content in XHTML can also be written in this way.">

Home >Web Front-end >HTML Tutorial >Issues that should be paid attention to when writing self-closing XHTML tags_HTML/Xhtml_Web page production

Issues that should be paid attention to when writing self-closing XHTML tags_HTML/Xhtml_Web page production

WBOY
WBOYOriginal
2016-05-16 16:45:28915browse

The img tag in XHTML should be written like this: . This writing method is also the so-called self-closing method, which is completely legal in XML. If you are familiar with XML-related development, you may be accustomed to this way of writing. Thinking that any element in XML that does not contain child nodes can be written in this way, then tags without content in XHTML can also be written in this way. XHTML theoretically allows any tag to be written in a self-closing method. However, browser compatibility has brought new problems, that is, IE cannot correctly recognize the self-closing writing method of some tags. String 8
Please try to enter the following XHTML code and browse it in IE:

hello world

. You will find that you can only see the hello in the front but not the world in the back. This is quite inexplicable. Yes. There may be many people who have encountered this problem and spent several hours on it but still can't find a reasonable explanation. String 4
The explanation comes from another similar piece of code:

hello world

. Can you see the display effect in IE and get a reasonable explanation? We can see that the hello in the front is displayed normally, while the world in the back is displayed in the textarea. This proves that IE does not correctly recognize that the textarea tag has closed itself. Instead, it treats the following content as a textarea when it is not closed. internal content.
At this time we understand why the previous code cannot see the world behind it, because it is recognized as part of the script. This shows that when we use XHTML, we cannot use self-closing writing as freely as XML. Only a few tags that do not need to be closed can be written in self-closing. Other tags are best used in pairs even if they do not have any content. closed writing method.
Finally, I need to remind everyone that in fact, IE is not the only one with weak parsers. In many places, you may encounter problems caused by loose parsers. Therefore, when writing XHTML, we still have to accommodate some inheritance from old HTML. Habit, you can't just write it casually like real XML because you think it meets the standards. Don’t believe it? Then try another one:

hello
world

, pay attention to the display effect in IE and Opera.
Some related specifications of XHTML:
1. All tags must have a corresponding closing tag
2. The names of all tag elements and attributes must be in lowercase
3. All XML tags must be reasonably nested
4. All attributes must be enclosed in quotation marks ""
5. Encode all 6. Give all Assign a value to the attribute
7. Do not use “--” in the comment content
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn