不用js,直接在HTML代码中,也可以要求不同的浏览器执行不同的HTML代码。
这里利用到IE注释。
<html>
<body>
<!--[if lte IE 7]>
<h1>这是版本小于等于7的Internet Explorer<br /></h1>
<![endif]-->
<!--[if gt IE 7]>
<h5>这是版本大于7的Internet Explorer<br /></h5>
<![endif]-->
<!--[if !IE]>-->
这不是Internet Explorer
<!--<![endif]-->
</body>
</html>
这样的IE注释,还可以大量用于JS与CSS文件的引用
<!--[if lt IE 9]>
<script src='demo1.js'></script>
<![endif]-->
<!--[if gte IE 9]>
<script src='demo2.js'></script>
<![endif]-->
<!--[if !IE]>-->
<script src='demo3.js'></script>
<![endif]-->