何时会<! - [if!IE]>使用? [英] When would <!--[if !IE]> be used?

查看:112
本文介绍了何时会<! - [if!IE]>使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天晚上我在IE7中调试了一些东西,当我键入<! - [if IE7]> ... 时,我在思考这个问题。对我而言,我见过<! - [if!IE]>



让我知道的是,据我了解,只有IE能够识别这些条件注释,所以要说 if not IE 没有意义,IE是否会看到并说Iam IE,所以这不适用于我?或者人们对哪些浏览器可以识别它感到困惑?

所以我的问题是。



你会在哪里使用<! - [if!IE]> ,目的是什么? AFAIK,其他浏览器将条件注释视为注释块(即,它们根本不被解析)。因此,这样的评论会在InternetExplorer之外的任何东西中发生(即包含CSS文件)(所以它与 [if IE] 条件注释相反)。在这样的评论中添加所有的CSS,看看IE的行为如何:P。





我刚刚检查过。这确实很愚蠢。由于< style> 标记位于CC中,所以其他浏览器根本不解析它,因此它根本不会被包含。 IE确实将其解释为啊哈,我是IE,所以我需要跳过这个。我能想到的唯一合理的解释是微软假设其他浏览器可能会开始解析条件注释。


I was pondering this question last night while debugging some things in IE7, when I typed in <!--[if IE7]>... it occured to me that I've seen <!--[if !IE]>.

Now what get me is that as far as I understand it, only IE recognises these conditional comments, so to to say if NOT IE makes no sense, does IE see this and say "Iam IE, so this doesn't apply to me?" or are people getting confused with which browsers can recognise it?

So my question is.

Where would you use <!--[if !IE]> and what is its purpose?

解决方案

AFAIK, other browsers treat conditional comments as comment blocks (ie, they aren't parsed at all). So, such a comment will make something happen (ie, include a CSS file) in anything EXCEPT Internet Explorer (so it's the inverse of the [if IE] conditional comments). Add all your CSS in such comments and see how IE behaves :P.

[EDIT]

OK, I just checked. This is indeed silly. Since the <style> tag is in the CC, other browsers don't parse it at all, so it effectively doesn't get included at all. IE indeed interprets this as "aha, I am IE so I need to skip this". The only reasonable explanation I can think of is Microsoft assuming at some point other browsers might start parsing conditional comments.

这篇关于何时会&lt;! - [if!IE]&gt;使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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