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

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

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

  • 相关阅读:
    Linux下NDK编译FFMPEG包含neon参数
    编译器优化陷阱——全局指针多次使用异常
    Linux下使用NDK编译FFMPEG(libstagefright)
    查看Android支持的硬解码信息
    图片格式转换
    转 MFC 主界面函数中线程等待避免界面卡死的处理方法
    Windows Shell编程实现重叠图标IconOverlay
    转 MFC中 GB2312、UTF-8、unicode 之间转换
    windows双机调试
    位图BITMAP结构
  • 原文地址:https://www.cnblogs.com/yyzyxy/p/7747040.html
Copyright © 2011-2022 走看看