2015-10-05 42 views

回答

4

參見decodeURIComponent

的decodeURIComponent()方法解碼先前由encodeURIComponent或通過類似的程序創建的統一資源標識符(URI)的組成部分。

var str = 'Fast-9%20|%20Speed%20(Something-Cool)'; 
 
alert(decodeURIComponent(str));

+0

但是,如果我想再次對其進行編碼,'|'符號變成'%7C '。如何避免這種情況? –

+0

@ArnasA。爲此,您需要使用正則表達式來根據您的要求來替換字符串!雖然'decodeURIComponent'和'encodeURIComponent'更全球化。 – Rayon

0

試試這個:

var str = 'Fast-9%20|%20Speed%20(Something-Cool)'; 
 
str = str.replace(/%20/g, " "); 
 
alert(str);

0
var decoded = decodeURIComponent("Fast-9%20|%20Speed%20(Something-Cool)"); 
相關問題