小编典典

对“除IE8”有条件的评论?

html

<!--[if IE 8]><![endif]-->用于定位IE8,但是除了IE8外,我还想为所有浏览器加载一些JS,我应该使用哪些条件注释?

编辑:我想知道这是否行得通: <!--[if lte IE 8]><![endif]-->

谢谢


阅读 300

收藏
2020-05-10

共1个答案

小编典典

我能想到一个把戏。在IE条件标签内设置一个变量,如果未设置该变量,请包含您的JS代码。

<script>
    var ie8 = false;
</script>

<!--[if IE 8]>
    <script>
        ie8 = true;
    </script>
<![endif]-->

<script>
    if (ie8 == false) {
        // any code here will not be executed by IE 8
        alert("Not IE 8!");
    }
</script>
2020-05-10