1. 程式人生 > >js轉義特殊字元

js轉義特殊字元

直接上程式碼
function jsEncode(url) {
    if(url){
        url = url.replace(/\%/g,"%25");
        url = url.replace(/\s/g,"%20");
        url = url.replace(/\+/g, "%2B");
        url = url.replace(/\#/g, "%23");
        url = url.replace(/\&/g, "%26");
        url = url.replace(/\=/g, "%3D");
        return url;
    }
}