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
  • 相关阅读:
    2020年寒假假期总结0210
    2020年寒假假期总结0209
    2020年寒假假期总结0208
    2020年寒假假期总结0207
    2020年寒假假期总结0206
    yolo-v4:Optimal Speed and Accuracy of Object Detection解析
    Docker 练习
    tensorflow2.0 GPU版本镜像文件
    flink项目实战
    高等数理统计知识点
  • 原文地址:https://www.cnblogs.com/lidgblogs/p/7124770.html
Copyright © 2011-2022 走看看