zoukankan      html  css  js  c++  java
  • encodeURI与decodeURI

    Global对象的ecodeURI方法可以对URI进行编码,与其类似的还有一个方法encodeURIComponent方法。

    相应的对URI的解码方法也有两个:decodeURI、decodeURIComponent, 下面将对这四个方法的用法做个简要介绍。

     

    encodeURI只对URI中的空格进行编码,所以decodeURI()方法主要用于对整个URI进行编码。

    encodeURIComponent会对URI中的所有非标准字符进行编码。

    所以decodeURIComponent()方法主要用于对URI中的某一段进行编码。比如对跟在URI后面的查询字符串的参数进行编码。

    举例说明:

    var uri = "http://www.cnblogs.com/lidgblogs/p/test 7124770.html";
    console.log(encodeURI(uri)); // http://www.cnblogs.com/lidgblogs/p/test%207124770.html
    console.log(encodeURIComponent(uri)); // http%3A%2F%2Fwww.cnblogs.com%2Flidgblogs%2Fp%2Ftest%207124770.html

    decodeURI: 只能对使用encodeURI编码的字符进行解码。

    decodeURIComponent: 只能对使用encodeURIComponent编码的字符进行解码。

    举例说明:

    var uri = "http%3A%2F%2Fwww.cnblogs.com%2Flidgblogs%2Fp%2Ftest%207124770.html";
    console.log(decodeURI(uri)); // http%3A%2F%2Fwww.cnblogs.com%2Flidgblogs%2Fp%2Ftest 7124770.html
    console.log(decodeURIComponent(uri)); // http://www.cnblogs.com/lidgblogs/p/test 7124770.html
  • 相关阅读:
    作品第二课----改变DIV任意属性的值
    今天遇到的mouseout和mouseleave之坑
    作品第二课----弹出层
    作品第二课----求数组中所有数字的和
    作品第二课----点击DIV显示其内容
    作品第二课----点击切换显示隐藏
    Linux 静态库与动态库
    Linux学习6-套接字
    Linux学习5-线程
    Linux学习4-信号
  • 原文地址:https://www.cnblogs.com/lidgblogs/p/7124770.html
Copyright © 2011-2022 走看看