wuk*_*ong 6 html internet-explorer
以下代码用于可靠的跨浏览器IE版本检测
<!--[if lt IE 7 ]><body class="ie_6"><![endif]-->
<!--[if IE 7 ]><body class="ie_7"><![endif]-->
<!--[if IE 8 ]><body class="ie_8"><![endif]-->
<!--[if IE 9 ]><body class="ie_9"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<body>
<!--<![endif]-->
Run Code Online (Sandbox Code Playgroud)
我不明白的是,为什么它正在工作.为什么法线<body>没有覆盖,<body class="ie_9">因为它只是一个普通的标签,应该被所有浏览器识别.
什么是魔术
<!-->
<body>
<!--
Run Code Online (Sandbox Code Playgroud)
Joe*_*Joe 11
您可能想要更改!(IE)为(!IE)
此外,<body>您正在谈论的"正常" 标签是有条件的评论.事实上,它在不同的行上并不重要,它仍然在条件注释标记内,因此受到影响.
IE的条件注释通过使用普通的HTML注释来工作,<!-- -->因此"false"条件中的任何代码都被注释掉了; <!-- <body class="ie6"> -->IE然后在其中有自己的语法.因此,非IE浏览器只看到一个注释字符串,IE将其视为要执行的语句.
因此,只显示一个正文标记,并且只使用该标记.
更多解释
<!--[if (gt IE 9)|!(IE)]><!-->
<body>
<!--<![endif]-->
Run Code Online (Sandbox Code Playgroud)
对于IE,这说:
<if greater than ie9, or not ie> (ie conditional comment)
<!--> (empty comment) (--> putting this here to stop SO ruining syntax highlighting :D)
<body>
<end if> (ie conditional comment)
Run Code Online (Sandbox Code Playgroud)
如果你不明白为什么,请阅读从"IE工作的条件评论......"开始的段落.
与任何其他浏览器相同的块看起来像这样:
<!--[if (gt IE 9)|!(IE)]><!--> (this is just one comment, containing the text "[if (gt IE 9)|!(IE)]><!")
<body>
<!--<![endif]--> (again, just one comment, containing "<![endif]")
Run Code Online (Sandbox Code Playgroud)