问什么要控制这个呢?很明显,加上这个元素能够告诉浏览器用什么模式来渲染页面,有时候我们在IE高版本的浏览器中显示正常,到了低版本排版就乱了,加上下面的和正确的DTD声明就可以了。
判断当前页面的文档模式
1 2 3 4 5 6 7 8 9 function detect() {10 var mode = document.documentMode;11 switch (mode) {12 case 5:13 alert('Internet Explorer 5 quirks mode');14 break;15 case 7:16 alert('Internet Explorer 7 Standards mode');17 break;18 case 8:19 alert('Internet Explorer 8 Standards mode');20 break;21 case 9:22 alert('Internet Explorer 9 Standards mode');23 break;24 case 10:25 alert('Internet Explorer 10 Standards mode');26 break;27 }28 29 }30 detect();31 32 33
S(标准模式)、A(接近标准模式)、Q(混杂模式)
Doctype NS6 Old Moz Moz & Safari & Opera 10 & IE10 & HTML5 Opera 9.0 IE 8, IE 9 & Opera 9.5 IE 7 & Opera 7.10 IE 6 & Opera 7.0 Mac IE 5 Konq 3.2 None Q Q Q Q Q Q Q Q Q Q S S S S A A A ? ? ? ? ? ? ? ? Q Q Q Q Q Q Q Q Q S S S S S A A A A S S S S S A A Q A S S S S S A A A A S S S S S A A A A Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q S S A A A A A A Q Q S A A A A A A Q Q Q Q Q A A A A Q S S S S S A A A A S S S S S A A A A S S S S S A A A A S S A A A A A A Q
S S S S S A Q A Q
S S S S S A Q A Q
S S S S S A Q A Q
S S A A A A Q A Q Q S S Q Q Q Q Q Q Q S S S S A A A Q S S S Q Q Q Q Q Q S S S S S A A A Q
PS:
Opera文档模式:http://www.opera.com/docs/specs/doctype/
Firefox文档模式:https://developer.mozilla.org/en-US/docs/Mozilla%27s_DOCTYPE_sniffing
IE8:http://blogs.msdn.com/b/ie/archive/2010/03/02/how-ie8-determines-document-mode.aspx
查看更多关于DTD与模式_html/css_WEB-ITnose的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did106243