JS的內置函數(encodeURIComponent();decodeURI())實現中文與URI間的轉換javascript
例子:html
<!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>
java