1. 程式人生 > >URL中文編碼亂碼

URL中文編碼亂碼

解決方法:encodeURI()

<script type="text/javascript">
    //編碼
     var url = encodeURI("http://www.qcby.com/傾城教育");
    document.write(url + "<br>");
    //解碼
    var url = decodeURI(url);
    document.write(url);
</script>


encodeURI不編碼字元有82個:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a- z,A-Z

執行結果: