JS的内置函数(encodeURIComponent();decodeURI())实现中文与URI间的转换
例子:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<mce:script type="text/javascript"><!--
function test(){
var str = document.getElementById("srcStr").value;
var strToUri = encodeURIComponent(str);
document.getElementById("strToUri").innerHTML = strToUri;
var uriToStr = decodeURI(strToUri);
document.getElementById("uriToStr").innerHTML = uriToStr;
}
// --></mce:script>
</head>
<body>
<p>要转换的文字:
<input type="text" id="srcStr" />
</p>
<p>
传换成的uri代码:
<textarea cols="30" rows="3" id="strToUri">
uri代码转换成文字: </pre>