---
title: "将浏览器中传递过去的字符串进行URI编码"
author: "digilover"
date: "2012-04-29T09:10:05Z"
tags: []
categories: ["Web前端"]
slug: "uri"
draft: false
lastmod: "2012-04-29T09:10:05Z"
id: 1503472
url: "https://digilover.iteye.com/blog/1503472"
---

encodeURI将浏览器中传递过去的字符串进行URI编码，浏览器中默认采用utf-8对中文编码，与jsp页面中设置的字符编码无关，decodeURI是其解码函数

&lt;script type="text/javascript"&gt;  
  var strURI=encodeURI("[http://www.digi.cn/in.jsp?name](http://www.digi.cn/in.jsp?name)=天逸&pass= aa");  
 var strURI2= decodeURI(strURI);  
  alert(strURI);  
    alert(strURI2);

&lt;/script&gt;

&lt;!--EndFragment--&gt;