Precautions for writing self-closing XHTML labels _ HTML/Xhtml _ webpage Creation

Source: Internet
Author: User
The img mark in XHTML should be written as follows: & lt; imgalt & quot; src & quot; & gt;. This method is called self-disabling, it is completely legal in XML. If you are familiar with XML-related development, you may also get used to this writing method, thinking that any element in XML that does not contain child nodes can be written in this way, then the labels without content in XHTML are also XHTMLThe img mark in should be written as follows: This writing method is called self-closing, which is completely legal in XML. If you are familiar with XML-related development, you may be used to this writing method, thinking that any element in XML that does not contain child nodes can be written in this way, the labels that do not have any content in XHTML can also be written in this way. In XHTML theory, of course, any label can be written in self-closing mode. However, browser compatibility brings about a new problem, that is, IE cannot correctly identify the self-closing method of some labels. String 8
Enter the following XHTML code and browse it in IE:

HelloWorld

You will find that you can only see the preceding hello but not the following world, which is quite undefined. Many people may have encountered this problem and could not find a reasonable explanation after several hours. String 4
The explanation is derived from another similar code:

HelloWorld </p>: Can you give a reasonable explanation of the display effect in IE? We can see that the preceding hello is displayed normally, while the following world is displayed in textarea, which proves that IE does not correctly identify that the textarea tag has been disabled, but when it is not disabled, the following content is recognized as the content inside textarea.
At this time, we can see why the previous Code does not see the world, because it is recognized as part of the script. This shows that when we use XHTML, we cannot use the self-closing method as if we were using XML. Only a few labels that do not need to be closed can be self-disabled, other labels should be closed in pairs even if there is no content.
Finally, we need to remind you that, in fact, mentally retarded parser not only has Internet Explorer, but may encounter problems caused by not rigorous parser in many places, therefore, when writing XHTML, we still need to accommodate some old HTML inherited habits. It cannot be written as if the XML was as self-satisfied as the standard. Believe it? Try again:

Hello

World

, Pay attention to the display effect in IE and Opera.
XHTML specifications:
1. All tags must have an ending mark.
2. The element and attribute names of all tags must be in lower case.
3. All XML tags must be reasonably nested.
4. All attributes must be enclosed by quotation marks ("").
5. Put all <和&特殊符号用编码表示
6. assign a value to all attributes
7. Do not make "--" in the comment content

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.