美文网首页
ie浏览器 条件注释,根据不同版本引入不同js

ie浏览器 条件注释,根据不同版本引入不同js

作者: _信仰zmh | 来源:发表于2018-04-19 20:31 被阅读463次

    ie浏览器,真心佩服ie,各种版本,浏览器的显示不同。

    关于jQuery lib对ie的兼容性

    ie1.9版本,是对ie8的最后兼容。

    也就是说jQuery2.0以下版本的都支持ie8,但是2.0以上(包含2.0版本)的jQuery库已经全面放弃了ie8浏览器。

    如果你的用户包含ie8用户,恰好你的项目中又引用了高版本的jq,那就需要对ie8进行判断。

    根据不同的版本,引入高低版本的jq库。

    ie条件注释

    条件注释是层叠样式表(CSS)用于区分IE特定版本的首选方式。
    重要提示 自IE10起,标准模式不再支持条件注释。而是采用特征检测给浏览器不支持的功能来提供备用策略。

    • expression是由功能、操作符和值组成的,下图是支持的功能,并介绍了每个功能支持的值。


      e1.png
    • 也可以添加表达式哦


      e21.png
    • 举个栗子:
      如果是ie8就引入1.9版本的jqueryLib,如果不是就引入其他版本的jqueryLib

       <!--[if IE 8]>
            <script src="http://code.jquery.com/jquery-1.9.1.min.js" ></script> 
         <![endif]-->
         
         <!--[if !(IE 8)]>
            <script  src="./WeChat/esmart/QU/js/jquery.js" ></script>   
         <![endif]-->
    

    如果判断不是的话,记得加个!(IE n)

    Downlevel-hidden条件注释类似于基本的HTML注释,包含连字符(“ - ”)在开启和关闭标签。条件显示在标签的开口部,和[ENDIF]被放置在标签的封闭部分之前。内容放在注释标签内。
    因为前四个字符和注释的最后三个字符是相同的HTML注释元素,所以低版本浏览器会忽略注释块内的HTML内容。由于内容被有效地不支持条件注释的浏览器隐藏,这种类型的条件注释被称为低版本隐藏。
    如果条件表达式的结果为真,则对注释块里面的内容进行分析,并通过Internet Explorer 5及更高版本的渲染。针对Internet Explorer而专门设计的内容,这种做法特别有效。

    • 更多栗子如下:
    <!--[if IE]><p>You are using Internet Explorer.</p><![endif]-->
    <![if !IE]><p>You are not using Internet Explorer.</p><![endif]>
    
    <!--[if IE 7]><p>Welcome to Internet Explorer 7!</p><![endif]-->
    <!--[if !(IE 7)]><p>You are not using version 7.</p><![endif]-->
    
    <!--[if gte IE 7]><p>You are using IE 7 or greater.</p><![endif]-->
    <!--[if (IE 5)]><p>You are using IE 5 (any version).</p><![endif]-->
    <!--[if (gte IE 5.5)&(lt IE 7)]><p>You are using IE 5.5 or IE 6.</p><![endif]-->
    <!--[if lt IE 5.5]><p>Please upgrade your version of Internet Explorer.</p><![endif]-->
    
    <!--[if true]>You are using an <em>uplevel</em> browser.<![endif]-->
    <![if false]>You are using a <em>downlevel</em> browser.<![endif]>
    
    <!--[if true]><![if IE 7]><p>This nested comment is displayed in IE 7.</p><![endif]><![endif]-->
    

    相关文章

      网友评论

          本文标题:ie浏览器 条件注释,根据不同版本引入不同js

          本文链接:https://www.haomeiwen.com/subject/qhdgkftx.html