


如果你熟悉XML相关的开发,可能也就习惯于这种写法,想着XML中任何不含子节点的元素都可以这样写,那么XHTML中没有内容的标签也都可以这样写。XHTML中理论上当然允许任何标签以自关闭的方法来书写,然而浏览器兼容性却带来了新问题,那就是IE无法正确识别某些标签的自关闭写法。
请尝试输入以下XHTML代码并在IE中浏览:<strong><font face="新宋体" size="3"><p>hello <script></script> world</p></font></strong>
,你会发现只能看到前面的hello而不见后面的world,这事情让人挺无法解释的吧。可能有不少人都曾经遇到过这个问题,并且花了几个小时在上面都找不到合理的解释。
解释源自另外一段类似的代码:<strong><font face="新宋体" size="3"><p>hello <textarea></textarea> world</p></font></strong>
,你在IE中看看其显示效果,能够得到合理的解释了吗?我们能够看到前面的hello正常显示了,而后面的world则显示在textarea里面,这证明IE并没有正确识别textarea标签已经自关闭了,而是当它没有关闭,并将后面的内容识别为textarea内部的内容。
这时候我们就明白前面那段代码为什么看不到后面的world了,因为它被当作script的一部分来识别了。这就说明了,在我们使用XHTML时并不能好像XML那样随意的使用自关闭的写法,只有少数原本不需要关闭的标签可以用自关闭的写法,其他标签即使没有任何内容最好也用成对的关闭写法。
最后需要提醒大家的是,其实弱智的parser不仅仅IE有,很多地方都可能碰到由于parser不严谨而引起的问题,所以我们在书写XHTML的时候还是要迁就一些老HTML继承下来的习惯,不能好像真的XML那样自以为符合标准了就随意写。不信?那么再试一个吧:<strong><font face="新宋体" size="3"><p>hello <br> world</p></font></strong>
,留意IE与Opera中的显示效果。
Update: Some readers think that the examples I gave do not comply with the XHTML specification, so please read XHTML specification. Chinese translation of the section Empty Elements As follows: "Empty elements must either have a closing tag or end with />, such as
or
. Please refer to HTML Compatibility Standard for information on ensuring backward compatibility with HTML4 browsers." As you can see,
is also given in the specification. Examples like hr> show that the writing method of
complies with the XHTML specification, but is not compatible with the HTML4 standard. So is XHTML compatible with HTML4? Let’s look at the section Compatibility Issues, Chinese The translation is as follows: "Although XHTML1.0 documents are not required to be compatible with existing browsers, in practice this is not difficult to achieve." Therefore, XHTML does not stipulate that documents must be backward compatible. The examples I gave are all Legal XHTML document fragments, when appearing in complete XHTML, can all pass W3C Markup Validation Service verification.
Update again: Actually, the purpose of writing this article is not to emphasize that only conforming to the XHTML specification is enough, nor is it to emphasize that conforming to XHTML and being compatible with HTML4 is enough, but that more needs should be considered Compatibility situation. For example, your CMS allows users to submit HTML, and the submitted HTML is formatted into XHTML through SgmlReader or other methods, and other XML processing may also be performed. At this time, it is possible to convert the submitted by the user into . In this case, it is not easy to find the problem through tracing and debugging, because XML processing does not violate any specifications, and each step of processing is semantic. In addition, it is best not to write
as
, because there are indeed some mentally retarded parsers that cannot correctly recognize just because there is one missing space.

This is the 3rd post in a small series we did on form accessibility. If you missed the second post, check out "Managing User Focus with :focus-visible". In

This tutorial demonstrates creating professional-looking JavaScript forms using the Smart Forms framework (note: no longer available). While the framework itself is unavailable, the principles and techniques remain relevant for other form builders.

The CSS box-shadow and outline properties gained theme.json support in WordPress 6.1. Let's look at a few examples of how it works in real themes, and what options we have to apply these styles to WordPress blocks and elements.

This article explores the top PHP form builder scripts available on Envato Market, comparing their features, flexibility, and design. Before diving into specific options, let's understand what a PHP form builder is and why you'd use one. A PHP form

If you’ve recently started working with GraphQL, or reviewed its pros and cons, you’ve no doubt heard things like “GraphQL doesn’t support caching” or

The Svelte transition API provides a way to animate components when they enter or leave the document, including custom Svelte transitions.

How much time do you spend designing the content presentation for your websites? When you write a new blog post or create a new page, are you thinking about

In this article we will be diving into the world of scrollbars. I know, it doesn’t sound too glamorous, but trust me, a well-designed page goes hand-in-hand


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download
The most popular open source editor

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
