博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
通过条件注释<!--[if IE]><!-->判断浏览器
阅读量:6924 次
发布时间:2019-06-27

本文共 1687 字,大约阅读时间需要 5 分钟。

有时我们会在网站头部看到:

<!--[if IE 7]>

<![endif]-->

或者

<!--[if lt IE 9]>

<![endif]-->

其他浏览器会将其作为注释而忽略这些语句,因为他们是IE专门提供的一种语法,如此就能根据不同的IE版本加载对应的CSS或者JS文件了。

除IE外都可识别

 

项目 范例 说明
! [if !IE] The NOT operator. This is placed immediately in front of the feature, operator, or subexpression to reverse the Boolean meaning of the expression.
NOT运算符。这是摆立即在前面的功能,操作员,或子表达式扭转布尔表达式的意义。
lt [if lt IE 5.5] The less-than operator. Returns true if the first argument is less than the second argument.
小于运算符。如果第一个参数小于第二个参数,则返回true。
lte [if lte IE 6] The less-than or equal operator. Returns true if the first argument is less than or equal to the second argument.
小于或等于运算。如果第一个参数是小于或等于第二个参数,则返回true。
gt [if gt IE 5] The greater-than operator. Returns true if the first argument is greater than the second argument.
大于运算符。如果第一个参数大于第二个参数,则返回true。
gte [if gte IE 7] The greater-than or equal operator. Returns true if the first argument is greater than or equal to the second argument.
大于或等于运算。如果第一个参数是大于或等于第二个参数,则返回true。
( ) [if !(IE 7)] Subexpression operators. Used in conjunction with boolean operators to create more complex expressions.
子表达式运营商。在与布尔运算符用于创建更复杂的表达式。
& [if (gt IE 5)&(lt IE 7)] The AND operator. Returns true if all subexpressions evaluate to true
AND运算符。如果所有的子表达式计算结果为true,返回true
| [if (IE 6)|(IE 7)] The OR operator. Returns true if any of the subexpressions evaluates to true.
OR运算符。返回true,如果子表达式计算结果为true。

 

<!--[if lt IE 9]>

加载CSS1
<!--[else]>
加载CSS2
<![endif]-->
这样有效是有效,但是用HTML VALIDATOR里,报错,因为这个不符合XHTML 1.1的规范,如果把ELSE语句去掉,则正确。

方法1:

加载CSS2

<!--[if lt IE 9]>
加载CSS1(可以把要重写的写在这里).
<![endif]-->

转载于:https://www.cnblogs.com/gxsyj/p/5947927.html

你可能感兴趣的文章
问对网:有价值的职场互助社区
查看>>
SQL Server 客户端连接的问题
查看>>
德勤收购MSSP厂商Vigilant
查看>>
Inode构建的ext3文件树
查看>>
如何让年轻员工乐于接受批评
查看>>
zabbix中文配置指南
查看>>
Microsoft Visual Studio下编译缺少头文件unistd.h解决办法
查看>>
关于密码那些事(二)
查看>>
Windows8/Silverlight/WPF/WP7/HTML5周学习导读(11月19日-11月25日)
查看>>
数据驱动安全架构升级---“花瓶”模型迎来V5.0(一)
查看>>
一道没人搞得定的趣味Shell编程游戏题!,看看你会不会?
查看>>
2011,我的IT我的梦
查看>>
SCOM2012部署系列之八:启用审核收集(ACS)
查看>>
自适应哈希索引引起的不定时MySQL崩溃重启
查看>>
zabbix企业应用之监控docker容器资源情况
查看>>
Exchange 2016集成ADRMS系列-6:域内OWA客户端测试
查看>>
python常用的几种GUI解析
查看>>
360公司面试记
查看>>
深入浅出OOP(二): 多态和继承(继承)
查看>>
51CTO学院四周年优秀讲师评选中,需要您的宝贵一票
查看>>