當你在使用JavaScript來做一些GET指令時你應該經常會發現一個問題就是JavaScript他會要求你把網址編碼吧,遇到這種需要編碼網址才能使用的函式你可以使用encodeURIComponent來幫網址進行編碼
. encodeURIComponent語法格式:
var 儲存用變數=encodeURIComponent("被加密網址").
.
範例:
在網址列貼上以下語法
javascript:alert(encodeURIComponent(location.href));
另外你可以使用decodeURIComponwent來把被encodeURIComponent編碼過的網址回復原狀
語法格式跟encodeURIComponent一樣都是:
var 儲存用變數=encodeURIComponent("被加密網址")



