encodeURI和decodeURI是成对来使用的,因为浏览器的地址栏有中文字符的话,可以会出现不可预期的错误,

所以可以encodeURI把非英文字符转化为英文编码,decodeURI可以用来把字符还原回来

一、基本概念 
encodeURI和decodeURI是成对来使用的,因为浏览器的地址栏有中文字符的话,可以会出现不可预期的错误,所以可以encodeURI把非英文字符转化为英文编码,

decodeURI可以用来把字符还原回来。encodeURI方法不会对下列字符进行编码:":"、"/"、";" 和 "?",encodeURIComponent方法可以对这些字符进行编码。 
decodeURI()方法相当于java.net.URLDecoder.decode(URIString, "UTF-8"); 
encodeURI()方法相当于java.net.URLEncoder.encode(URIString, "UTF-8");

二、例子

<script type="text/javascript">
var uriStr = "http://www.baidu.com?name=张三&num=001 zs";
var uriec = encodeURI(uriStr);
document.write("编码后的" + uriec);
var uridc = decodeURI(uriec);
document.write("解码后的" + uridc);
</script>

编码后的http://www.baidu.com?name=%E5%BC%A0%E4%B8%89&num=001%20zs 
解码后的http://www.baidu.com?name=张三&num=001 zs

最新文章

  1. 基础知识《十》unchecked异常和checked异常
  2. ex3-数字和数字计算
  3. [转]Oracle存在则更新,不存在则插入
  4. Leetcode Construct Binary Tree from Preorder and Inorder Traversal
  5. 【C51】UART串口通信
  6. lodash的源码(1)
  7. clojure
  8. oracle新建用户
  9. 007.Compiled
  10. MEMS微加工技术
  11. 神器Vim之命令介绍
  12. macaca 环境搭建篇,(web 和安卓)
  13. [Luogu 2062]分队问题
  14. 公司间INVOICE的库存设置
  15. Java案例-用户注册邮箱绑定激活功能实现
  16. websocket是什么
  17. Mac和Windows中常见中文字体的英文名称
  18. 闭区间套定理(Nested intervals theorem)讲解2
  19. navicat连接oracle失败
  20. html5式程序员表白

热门文章

  1. GitBlit集成AD域LDAP
  2. CSS学习摘要-数值和单位及颜色
  3. 解决 hibernate cannot define positional parameter after any named parameters have been defined
  4. 高性能网站架构缓存——redis集群
  5. 获取索引--------用range()和len()
  6. 激活office软件
  7. 面向对象程序设计_tesk1_寒假伊始
  8. BZOJ 2424 订货 最小费用流
  9. python第二十五课——闭包
  10. 学习python第四天——Oracle分组