DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> javascript中encodeURI和decodeURI方法使用介紹
javascript中encodeURI和decodeURI方法使用介紹
編輯:關於JavaScript     
一、基本概念
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
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved