The img tag in XHTML should be written like this: <img alt= src= />, which is the so-called self-closing, which is a completely legal way to write in XML. If you are familiar with XML-related development, you may be accustomed to this writing method, thinking that any element without child nodes in XML can be written like this, then tags without content in XHTML can also be written like this. In theory, any tags are allowed to be written in a self-closed way, but browser compatibility brings new problems, that is, IE cannot correctly identify the self-closed way of writing certain tags. String 8
Please try to enter the following XHTML code and browse it in IE: <p>hello <script type=text/javascript /> world</p>, and you will find that you can only see the hello in front but not the world in the back. This is quite unexplainable. Many people may have encountered this problem before and spent several hours finding a reasonable explanation on it. String 4
The explanation comes from another similar code: <p>hello <textarea /> world</p>. Can you get a reasonable explanation when you look at its display effect in IE? We can see that the hello in the front is displayed normally, while the world in the back is displayed in the textarea, which confirms that IE does not correctly recognize that the textarea tag has been closed, but when it is not closed, it recognizes the content behind as the content inside the textarea.
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 the self-closing writing method as casually as XML. Only a few tags that did not need to be closed can be written in self-closing. It is best to use pairs of other tags even if there is no content.
Finally, I need to remind you that in fact, there are not only IEs for mentally retarded parsers, but many places may encounter problems caused by the lack of rigor of parsers. Therefore, when writing XHTML, we should still accommodate the habit of continuing the old HTML. We cannot just write as if XML is really as self-consistent with the standards. Don't believe it? Then try another one: <p>hello <br></br> world</p>, pay attention to the display effect in IE and Opera.
Some related specifications of XHTML:
1. All markers must have a corresponding end mark
2. All label elements and attribute names must be in lowercase
3. All XML tags must be reasonably nested
4. All attributes must be enclosed in quotes
5. All < and & extraordinary symbols are expressed in code
6. Assign a value to all attributes
7. Do not use it in the comment content-