"IE8除外"的条件评论?

3zz*_*zzy 6 html javascript conditional comments internet-explorer-8

<!--[if IE 8]><![endif]-->用于针对IE8,但是我想为所有浏览器加载一些JS,除了IE8,我应该使用什么条件评论?

编辑:我想知道这是否会奏效: <!--[if lte IE 8]><![endif]-->

谢谢

bob*_*nce 19

我想为所有浏览器加载一些JS,除了IE8,我应该使用什么条件评论?

对于不支持CC的"其他浏览器"中显示的内容,您需要一个下层显示的条件注释.

<!--[if !IE 8]><!-->
    ....
<!--<![endif]-->
Run Code Online (Sandbox Code Playgroud)

(这与Microsoft的官方语法略有不同,后者不是有效的HTML.)

"IE8以外的所有浏览器"都是一个不寻常的要求,你确定这是你想要的吗?IE的未来版本怎么样?


Sid*_*ddy 13

我可以想到一个技巧.在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>
Run Code Online (Sandbox Code Playgroud)