以下是针对 Internet Explorer 9+ 和所有非 IE 浏览器的经典条件注释:
<!--[if gt IE 8]><!-->
IE 9+ and all non-IE browsers see this text.
<!--<![endif]-->
这 4 个部分各自的用途是什么?
<!--[if gt IE 8]>
<!-->
<!--
<![endif]-->
最佳答案
它们是带有条件语句和运算符的 HTML 注释。让我来分解一下:
<!--[if gt IE 8]><!-->
gt
这里的意思是“大于,并且IE
”表示 Internet Explored,以及后面的版本。这:
<!--<![endif]-->
表示结束条件语句。此特定语法不同于常规 HTML 兼容语法:
<!--[if condition]>-->
Stuff here
<!--<![endif]-->
由于以下原因,来自SitePoint :
IE7 and later browsers will also reveal the
-–>
after the opening conditional statement. The fix suggested by Microsoft is to add an extra<!
just after the opening conditional comment.
这意味着 -->
之后<!--[if condition]>
由 IE 7+ 浏览器解释。您给出的评论用于解决这一问题。阅读有关条件注释的更多信息 at Microsoft's MSDN .
关于IE 的 JavaScript 条件注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39671505/