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
  • 相关阅读:
    printf里的=、++
    线程也疯狂-----异步编程
    自己搭建node服务器环境(请求静态资源、get请求、post请求)
    React学习
    2020.10-2021-01总结
    接圈的作用和缺点
    CWnd,HWND; CDC,HDC
    Python通过requests模块处理form-data请求格式
    element-ui resetFields 无效的问题
    用python 将数字每三组分割
  • 原文地址:https://www.cnblogs.com/lidgblogs/p/7124770.html
Copyright © 2011-2022 走看看