如果在doctype声明中没有提及,什么是默认的DTD? [英] What's default DTD if not mentioned in doctype declaration?

查看:99
本文介绍了如果在doctype声明中没有提及,什么是默认的DTD?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的页面中,doctype被声明为:

 <!DOCTYPE HTML PUBLIC -  // W3C // DTD HTML 4.01 Transitional // EN> 

没有明确指定DTD。
我不知道在IE中哪个DTD会被默认?

看起来不像

pre> http://www.w3.org/TR/html4/loose.dtd

因为我在添加了loose.dtd后,页面中的表格被打破了。
任何人都可以解释这个吗?
Thanks!

解决方案

通过SGML标准,您的文档类型声明通过命名来指定文档类型定义,如由W3C注册。但是,通过 HTML 4.01规范,文档必须有三种可选的文档类型声明之一,并且它们都包含一个URL。



这就是这样的理论,因为浏览器实际上没有读取的DTD。他们将文档类型声明视为魔术字符串,在文档类型嗅探中处理。但是,在大多数浏览器中,浏览器模式的选择受HTML 4.01 Transitional魔术字符串中是否存在URL影响。当它不存在时,它们在怪癖模式中运行。当它出现时,大多数浏览器都以标准模式或几乎标准模式运行。

怪癖模式意味着大量不同的怪癖,所以切换的效果从它到标准模式可能意味着任何事情(从无效果到完全灾难变化)。这种转换通常需要仔细检查,如果不是重写,整个文档。


In my page, the doctype is declared as:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

no DTD is explicitly specified. I wonder in IE which DTD will be defaulted?

seems it does not behave the same as

"http://www.w3.org/TR/html4/loose.dtd"

since my table in the page was broken after I added the loose.dtd. Can anyone help explain this? Thanks!

解决方案

By the SGML standard, your document type declaration specifies a Document Type Definition by naming it, as registered by the W3C. However, by the HTML 4.01 spec, a document must have one of three alternative document type declarations, and all of them contain a URL, too.

This is as such just theory, since browsers don’t actually read DTDs. They treat document type declarations just as magic strings, in doctype sniffing. However, in most browsers, the choice of a browser’s mode is affected by the presence or absence of a URL in that magic string for HTML 4.01 Transitional. When it is absent, they operate in Quirks Mode. When it is present, most browsers operate in "standards mode" or "almost standards mode".

Quirks Mode means a large number of different quirks, so the effect of switching from it to "standards mode" may imply just about anything (varying from no effect to complete disaster). Such a switch generally requires a careful check, if not rewrite, of the entire document.

这篇关于如果在doctype声明中没有提及,什么是默认的DTD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆