IE hack 条件语句

只在固定IE版本下执行

将以下代码放在head标签中,在script标签中写js即可

<!--[if IE 8]>
    <script>
        console.log("in ie8")
        $(function(){
            // ......
        })
   </script>
<![endif]-->

注意:需要在文档加载完后再执行,要将代码写在$(function(){......})

其它写法

<!--[if IE 8]><![endif]-->    //只在IE8下执行
<!--[if  lte IE 8]><![endif]-->    //在IE8及IE8以下版本执行
<!--[if  gte IE 8]><![endif]-->    //在IE8及IE8以上版本执行

要注意空格,否则可能出错

posted @ 2018-02-02 12:34  zhangce  阅读(136)  评论(0编辑  收藏  举报