下面一段代码是测试在微软的IE浏览器下的条件注释语句的效果:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>IE条件注释</title>
</head>
<body>
<!--[if IE]>
<h1>您正在使用IE浏览器</h1>
<![endif]-->
<!--[if IE 5]>
<h1>版本 5</h1>
<![endif]-->
<!--[if IE 5.0]>
<h1>版本 5.0</h1>
<![endif]-->
<!--[if IE 5.5]>
<h1>版本 5.5</h1>
<![endif]-->
<!--[if IE 6]>
<h1>版本 6</h1>
<![endif]-->
<!--[if IE 7]>
<h1>版本 7</h1>
<![endif]-->
<!--[if IE 8]>
<h1>版本 8</h1>
<![endif]-->
<!--[if IE 9]>
<h1>版本 9</h1>
<![endif]-->
</body>
</html>
下面的代码是在非IE浏览器和IE6下运行的条件注释:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>IE条件注释</title>
</head>
<body>
<!--[if !IE]><!-->
您使用的不是 Internet Explorer
<!--<![endif]-->
<!--[if IE 6]><!-->
您正在使用Internet Explorer version 6或者 一个非IE 浏览器
<!--<![endif]-->
</body>
</html>
下面是条件注释的语法:
[list]
[*]gt /Greater than/大于/<!--[if gt IE 5.5]>
[*]gte /Greater than or equal to/大于等于/<!--[if gte IE 5.5]>
[*]lt /Less than/小于/<!--[if lt IE 5.5]>
[*]lte /Less than or equal to/小于等于/<!--[if lte IE 5.5]>
[*]! /Note/不等于/<!--[if !IE 5.5]>
[/list]