The self-closing of XHTML tags should be noted

Source: Internet
Author: User

The IMG tags in XHTML should be written like this: This is the so-called self shutdown, which is perfectly legal in XML. If you are familiar with XML-related development, you may also be accustomed to writing, thinking that any element that does not have a child node in XML can be written in this way, so that tags with no content in XHTML can be written as well. XHTML, of course, allows any tag to be written in a closed way, but browser compatibility poses a new problem, IE does not correctly recognize the custom of some tags.

Please try entering the following XHTML code and browsing in IE: <p>hello <script type= "Text/javascript"/> World</p> You will find that you can only see the front of hello but not the back of the world, this thing is very inexplicable. There may be a lot of people who have had this problem and spent a few hours on it and couldn't find a reasonable explanation.

The explanation comes from another piece of code similar to this: <p>hello <textarea/> world</p> Do you see the display effect in IE, can you get a reasonable explanation? We can see the previous Hello normal display, and the world behind it is shown in textarea, which proves that IE did not correctly identify the TEXTAREA tag has been closed, but when it is not closed, and the following content is recognized as textarea internal content.

That's when we know why the previous code doesn't see the world in the back because it's being identified as part of the script. This means that when we use XHTML, we do not use the same way as XML, and only a handful of tags that do not need to be closed can be written in a closed form, and other tags, even if there is no content, are best used in pairs.

Finally need to remind everyone is that, in fact, the parser of the mentally retarded not only ie, many places may encounter due to the parser of the problem, so we are writing XHTML or to accommodate some old HTML inherited habits, You can't just write as if you think you can do it as if you were really XML. Don't believe it? Then try one more: <p>hello <br></br> World</p> Pay attention to the display effect of IE and opera.

Some relevant specifications of XHTML:

1. All tags must have a corresponding end tag

2. All label elements and attributes must be named with lowercase

3. All XML tags must be nested properly

4. All attributes must be enclosed in quotation marks ""

5. Encode all < and & special symbols

6. Assign a value to all properties

7. Do not in the annotation content to make "--"

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.