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;得到了同样的结果。

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

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

  • 相关阅读:
    软件开发规范
    Fail2ban + firewalld 防护doss攻击
    SourceTree&Git部分名词解释
    训子
    一个网络下,手机如何访问本地网址
    tempalte.js的一般用法
    template.js的介绍
    获取URL中的参数
    js判断苹果和安卓端或者wp端
    HTML5与WebGL编程
  • 原文地址:https://www.cnblogs.com/yyzyxy/p/7747040.html
Copyright © 2011-2022 走看看