HTTP URL编码和解码

HTTP URL编码和解码

注释:ECMAScript v3 已从标准中删除了 unescape() 函数,并反对使用它,因此应该用 decodeURI() 和 decodeURIComponent() 取而代之。

encodeURI() + decodeURI()

decodeURI() 函数可对 encodeURI() 函数编码过的 URI 进行解码。

示例:
<script type="text/javascript">

    var test1="http://www.w3school.com.cn/My+ first++/"

    //编码
    document.write(encodeURI(test1)+ "<br />")

    //解码
    document.write(decodeURI(test1))

</script>

编码结果:http://www.w3school.com.cn/My+%20first++/
解码结果:http://www.w3school.com.cn/My+ first++/

encodeURIComponent() + decodeURIComponent()

decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码

示例:

<script type="text/javascript">

    var test1="http://www.w3school.com.cn/My+ first++/"

    //编码
    document.write(encodeURIComponent(test1)+ "<br />")

    //解码
    document.write(decodeURIComponent(test1))

</script>

编码结果:http%3A%2F%2Fwww.w3school.com.cn%2FMy%2B%20first%2F
解码结果:http://www.w3school.com.cn/My+ first/

  转载请注明: Stone-Lee HTTP URL编码和解码

 上一篇
每天必读的七句话 每天必读的七句话
每天必读的七句话 1.不要跟任何人解释自己。 2.别让他人成为生命中的优先。 3.享受生命每个当下。 4.不要让在乎我们的人为我们哭泣。 5.别在喜悦时许下承诺、忧伤时做出回答、愤怒时做出决定。 6.当你持续地说非常忙碌,你的
2018-03-17
下一篇 
书读了会忘,那读书还有什么意义(摘录) 书读了会忘,那读书还有什么意义(摘录)
书读了会忘,读书的意义          “当我还是个孩子时,我吃过很多的食物,现在已经记不起来吃过什么了。但可以肯定的是,它们中的一部分已经长成了我的骨头
2018-03-17
  目录