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

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

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

  • 相关阅读:
    Java多线程知识-Callable和Future
    C#程序集Assembly学习随笔(增补版,附图)_AX
    C#程序集Assembly学习随笔(第一版)_AX
    【.Net】 C#访问修饰符
    访问修饰符(C# 编程指南)
    Restful API 架构与设计参考原则
    RESTful API 设计指南
    WebService的两种方式SOAP和REST比较
    公众号
    es6(const、let)
  • 原文地址:https://www.cnblogs.com/yyzyxy/p/7747040.html
Copyright © 2011-2022 走看看