如果IE >= 9或不IE的条件指令

Conditional directives for if IE >= 9 or not IE

本文关键字:IE 或不 指令 条件 如果      更新时间:2023-09-26

我正在开始一个新项目,遗憾的是我必须支持IE7 &IE9。最终,我将能够移除对IE7的支持,但希望能以一种平稳的方式移除它。

本质上,我希望尽可能使用最新版本的库。

<!--[if lt IE 9]>
    <script src="https://raw.githubusercontent.com/aFarkas/html5shiv/master/dist/html5shiv.min.js"></script>
    <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<![endif]-->
<!--[if gte IE 9]>
    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<![endif]-->
<!--[if !IE]><!-->
    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<!--<![endif]-->
<!--[if lt IE 8]>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/json3/3.3.1/json3.min.js"></script>
<![endif]-->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js"></script>
<!--[if lt IE 9]>
    <script src="local/angularjs-attribute-polyfill.js"></script>
<![endif]-->

正如你所看到的,我有两次JQuery库,一次是IE9,一次是不等于其他浏览器的IE…有什么好的方法来巩固这些吗?

可以使用

<!--[if gte IE 9]><!-->
    <script src="...jquery-2.1.1.min.js"></script>
<!--<![endif]-->

如果使用IE9或更高版本,此条件注释将允许包含脚本…而非ie浏览器无论如何都会忽略注释,只包含脚本,不问任何问题。