zoukankan      html  css  js  c++  java
  • javascript——URI的编解码方法

         度过了一个长长的假期,刚回到公司有些不适应了,之前的学习计划和工作计划都被打断了,回来都不知道要干什么啦。于是就跑去看同事的blog,又回来看之前自己记的笔记,接下来继续学习JavaScript吧。

         有效的URI(统一资源标示符)是不能包含某些字符的,如空格,所以需要进行编码,编码方法有:encodeURI()和encodeURIComponent(),

        对编的码进行解码方法有:decodeURI()和decodeURIComponent()。

        encodeURI()编的码只能decodeURI()解

        encodeURIComponent()编的码只能decodeURIComponent()解,

        encodeURI():用于编码完整的URI,它不对URI中的特殊字符进行编码:例如冒号、前斜杠、问号、英镑符号     

    
    
     var str0=encodeURI("http://www.cnblogs.com/ 2012/ 71.html");
         结果:http://www.cnblogs.com/%202012/%2071.html
          只对空格进行了编码

        encodeURIComponent():用于编码URI的某一部分,它对URI中的所有非标准字符进行编码

    var str1=encodeURIComponent("http://www.cnblogs.com/ 2012/ 71.html");
        结果:http%3A%2F%2Fwww.cnblogs.com%2F%202012%2F%2071.html
         对所有非标准字符进行编码
  • 相关阅读:
    Study Plan The Twelfth Day
    Study Plan The Fifteenth Day
    Study Plan The Seventeenth Day
    Study Plan The Tenth Day
    Study Plan The Eighth Day
    Study Plan The Eleventh Day
    Study Plan The Sixteenth Day
    Study Plan The Thirteenth Day
    Study Plan The Fourteenth Day
    Study Plan The Ninth Day
  • 原文地址:https://www.cnblogs.com/greenteaone/p/2933904.html
Copyright © 2011-2022 走看看