if判断IE浏览器的类型

有时候需要用到IF判断

在IE CSS hack(更多方法)当中常用到if IE 来判断浏览器的类型,解决CSS甚至于JS的兼容性问题,之前大家可能知道if IE来解决CSS的兼容性问题,其实if IE不仅仅是用于CSS hack的使用,我们在前端开发中甚至可以使用if IE来做JS的处理,如下面的代码:

引用<!–[if IE 5]> <script>document.write(”仅IE5.0与IE5.5可以识别”);</script> <![endif]–>

<!–[if gte IE 5.0]><script>document.write(”IE5.0以及IE5.0以上版本都可以识别”);</script><![endif]–>

<!–[if IE 6]><script>document.write(”仅IE6可识别”);</script><![endif]–>

<!–[if lt IE 6]><script>document.write(”IE6以下版本可识别”);</script><![endif]–>

<!–[if gte IE 6]><script>document.write(”IE6以及IE6以上版本可识别”);</script><![endif]–>

<!–[if IE 7]><script>document.write(”仅IE7可识别”);</script> <![endif]–>

<!–[if lt IE 7]><script>document.write(”IE7以下版本可识别”);</script><![endif]–>

<!–[if gte IE 7]><script>document.write(”IE7以及IE7以上版本可识别”);</script><![endif]–>

下面对if IE做一下详细的解释:


lte:就是Less than or equal to的简写,也就是小于或等于的意思。

lt :就是Less than的简写,也就是小于的意思。

gte:就是Greater than or equal to的简写,也就是大于或等于的意思。

gt :就是Greater than的简写,也就是大于的意思。

! :就是不等于的意思,跟javascript里的不等于判断符相同

当然我们也可以使用if IE的注释来引入 js文件,以及CSS hack(更多方法)文件,如下面的代码:

<!–[if lte IE 6]>
<!– 如果IE浏览器版本小于等于6,调用ie6.css样式表 –>
<link rel=”stylesheet” type=”text/css” href=“http://www.js8.in/ie6.css” />
<![endif]–>

<!–[if lte IE 6]>
<!– 如果IE浏览器版本小于等于6,调用ie6.js样式表 –>
<script type=”text/javascript” src=”http://www.js8.in/ie6.js“></script>
<![endif]–>

posted @ 2012-06-19 17:10  kingwell  阅读(355)  评论(0编辑  收藏  举报