zoukankan      html  css  js  c++  java
  • 低版本浏览器支持HTML5标签的方法

    最近刷了一道面试题,是关于低版本浏览器支持HTM5标签的写法,在网上找了一些,都行之有效,但是缺少整体总结,所以在这里总结一下,方便其他人过来阅读。

    IE低版本需要支持HTML5标签:

    方法1.传统引入js

    [javascript] view plain copy
     
     print?
    1. <!--[if IE]><script src="style/js/html5.js"></script><![endif]-->  

    注:js包(html5.js)内容:

    [javascript] view plain copy
     
     print?
    1. // html5shiv MIT @rem remysharp.com/html5-enabling-script  
    2. // iepp v1.6.2 MIT @jon_neal iecss.com/print-protector  
    3. /*@cc_on(function(m,c){var z="abbr|article|aside|audio|canvas|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video";function n(d){for(var a=-1;++a<o;)d.createElement(i[a])}function p(d,a){for(var e=-1,b=d.length,j,q=[];++e<b;){j=d[e];if((a=j.media||a)!="screen")q.push(p(j.imports,a),j.cssText)}return q.join("")}var g=c.createElement("div");g.innerHTML="<z>i</z>";if(g.childNodes.length!==1){var i=z.split("|"),o=i.length,s=RegExp("(^|\s)("+z+")", 
    4. "gi"),t=RegExp("<(/*)("+z+")","gi"),u=RegExp("(^|[^\n]*?\s)("+z+")([^\n]*)({[\n\w\W]*?})","gi"),r=c.createDocumentFragment(),k=c.documentElement;g=k.firstChild;var h=c.createElement("body"),l=c.createElement("style"),f;n(c);n(r);g.insertBefore(l, 
    5. g.firstChild);l.media="print";m.attachEvent("onbeforeprint",function(){var d=-1,a=p(c.styleSheets,"all"),e=[],b;for(f=f||c.body;(b=u.exec(a))!=null;)e.push((b[1]+b[2]+b[3]).replace(s,"$1.iepp_$2")+b[4]);for(l.styleSheet.cssText=e.join(" ");++d<o;){a=c.getElementsByTagName(i[d]);e=a.length;for(b=-1;++b<e;)if(a[b].className.indexOf("iepp_")<0)a[b].className+=" iepp_"+i[d]}r.appendChild(f);k.appendChild(h);h.className=f.className;h.innerHTML=f.innerHTML.replace(t,"<$1font")});m.attachEvent("onafterprint", 
    6. function(){h.innerHTML="";k.removeChild(h);k.appendChild(f);l.styleSheet.cssText=""})}})(this,document);@*/  



    方法2.在hmtl 加入(推荐)

    [javascript] view plain copy
     
     print?
    1. /*html5 tag*/  
    2. <!--[if lt IE 9]>  
    3.         <script>(function(tags){for(var i=0; i<tags.length; i++)document.createElement(tags[i]);})(["article","aside","details","figcaption","figure","footer","header","hgroup","nav","section","menu","video"]);</script>  
    4. <![endif]-->  

     

    什么是浏览器兼容:

    当我们使用不同的浏览器(Firefox IE7 IE6)访问同一个网站,或者页面的时候,会出现一些不兼容的问题,有的显示出来正常,有的显示出来不正常,我们在编写CSS的时候会很恼火,刚修复了这个浏览器的问题,结果另外一个浏览器却出了新问题。而兼容就是一种办法,能让你在一个CSS里面独立的写支持不同浏览器的样式。这下就和谐了!

    有一点逻辑思想的人都会知道可以用IE和FF的兼容结合起来使用。

    下面介绍三个兼容,例如:(适合新手,呵呵,高手路过。)

    [css] view plain copy
     
     print?
    1. _height:100px; //ie6  
    2. *height:100px;  //ie7    一般放在ie6前面  
    3. height:100px 9;  //ie9  
    4. -moz-height:100px    //ff  
    5. -webkit-height:100px   //-webkit- 浏览器引擎:Safari,chrome,qq,opers....  

    IE的if条件Hack

    [css] view plain copy
     
     print?
    1. 1. 〈!--[if !IE]〉〈!--〉 除IE外都可识别 〈!--〈![endif]--〉   
    2. 2. 〈!--[if IE]〉 所有的IE可识别 〈![endif]--〉   
    3. 3. 〈!--[if IE 5.0]〉 只有IE5.0可以识别 〈![endif]--〉   
    4. 4. 〈!--[if IE 5]〉 仅IE5.0与IE5.5可以识别 〈![endif]--〉   
    5. 5. 〈!--[if gt IE 5.0]〉 IE5.0以及IE5.0以上版本都可以识别 〈![endif]--〉   
    6. 6. 〈!--[if IE 6]〉 仅IE6可识别 〈![endif]--〉   
    7. 7. 〈!--[if lt IE 6]〉 IE6以及IE6以下版本可识别 〈![endif]--〉   
    8. 8. 〈!--[if gte IE 6]〉 IE6以及IE6以上版本可识别 〈![endif]--〉   
    9. 9. 〈!--[if IE 7]〉 仅IE7可识别 〈![endif]--〉   
    10. 10. 〈!--[if lt IE 7]〉 IE7以及IE7以下版本可识别 〈![endif]--〉   
    11. 11. 〈!--[if gte IE 7]〉 IE7以及IE7以上版本可识别 〈![endif]--〉  



    注:gt = Great Then 大于 

    〉 = 〉 大于号 

    lt = Less Then 小于 

    〈 = 〈 小于号 

    gte = Great Then or Equal 大于或等于 

    lte = Less Then or Equal 小于或等于

    吾生有涯 而知也无涯矣
  • 相关阅读:
    现在的代码,贴一下
    2014年七月写过的代码,现在看来,还有待改进呀
    第一次做技术论坛发博文,不知道说点啥
    04-树6. Huffman Codes--优先队列(堆)在哈夫曼树与哈夫曼编码上的应用
    04-树5. File Transfer--并查集
    04-树4. Root of AVL Tree-平衡查找树AVL树的实现
    03-树3. Tree Traversals Again (25)将先序遍历和中序遍历转为后序遍历
    03-树2. List Leaves (25) 二叉树的层序遍历
    二叉树的遍历:先序中序后序遍历的递归与非递归实现及层序遍历
    最大子序列和问题之算法优化
  • 原文地址:https://www.cnblogs.com/Sherlock09/p/7064719.html
Copyright © 2011-2022 走看看