zoukankan      html  css  js  c++  java
  • encodeURIComponent方法

    在使用encodeURIComponent此方法时,出现了如下奇怪的现象。

    1.

    http://www.w3school.com.cn/tiy/t.asp?f=jseg_encodeURIComponent

    在w3school的网站上,得到如下结果。

    document.write(encodeURIComponent("©")+"<br />");                                                       //%26%23169%3B
    document.write(encodeURIComponent("&#169;")+"<br />");                                              //%26%23169%3B
    document.write(decodeURIComponent("%26%23169%3B")+"<br />");                             //©,                                                  但是我自己去使用此方法解析时却是&#169;

    2.在菜鸟教程的网站上:http://www.runoob.com/try/try.php?filename=tryjsref_encodeuricomponent

    document.write(encodeURIComponent("©"));                                                                         %C2%A9

    此时利用   %C2%A9去解码反倒是得到了正确的解析,即©。

    document.write(decodeURIComponent("%26%23169%3B")+"<br />");                             //©
    document.write(decodeURIComponent("%C2%A9")+"<br />");                                          //©

    3.在谷歌开发者工具中控制台键入

    encodeURIComponent("©");
    "%C2%A9"

    decodeURIComponent("%C2%A9")
    "©"

    decodeURIComponent("%26%23169%3B")
    "&#169;"

    最终:

    个人认为w3school上的编码方法出错,因为对©和&#169;得到了同样的结果。

    同样的,菜鸟教程中的解码时,都会解析出©,也不准确。

    所以要使用的话,为了保证编码解码的对应的唯一性,请以谷歌开发者工具结果为准。

  • 相关阅读:
    Docker 设置阿里云镜像
    Linux 安装Navicat Premium 15
    Ubuntu常用工具安装
    Docker安装MongoDB、MySQL、Jenkins、Gitlab、Nginx
    Ubuntu18.04修改apt-get源
    Spring定时任务
    Quartz学习总结
    cron表达式
    将VirtualBox里安装的虚拟机在后台运行方法(在状态栏隐藏窗口)
    npm小结
  • 原文地址:https://www.cnblogs.com/yyzyxy/p/7747040.html
Copyright © 2011-2022 走看看