escape ,unescape 不再使用了,使用encodeURIComponent吧

getUrlParam = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return decodeURIComponent(r[2]); return null;
}



var nickName = $.getUrlParam("nickName");
var encodedKey = encodeURIComponent(nickName);
document.location.href = "/activity/join?nickName=" + nickName

爲什麼使用encodeURIComponent呢,下面這張圖片可以告訴你哦!!!

 上圖可見,encodeURIComponent可以轉譯的更多,包括特殊字符。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章