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

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

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

  • 相关阅读:
    两个序列最大子集公共和问题
    两个随机变量相关系数
    多项分布的定义
    算法分析结课总结回溯算法
    潜语义分析LSA相比向量空间模型VSM改变了什么
    类对象的声明和类对象指针的申请的种种
    C#中 常用的方法
    转:GridView鼠标移动行变色 (http://www.cnblogs.com/lovenets/articles/808071.html)[同ceng]
    WinForm 获取指定行列的Value
    华丽丽的分隔符
  • 原文地址:https://www.cnblogs.com/yyzyxy/p/7747040.html
Copyright © 2011-2022 走看看