我正在尋找來自PHP的urlencode()
類似的功能,只需在JavaScript中。 jQuery庫是允許的。來自PHP的urlencode()在JavaScript中?
基本上,我需要對字符串進行編碼,然後用JavaScript將用戶重定向到另一個頁面。
我正在尋找來自PHP的urlencode()
類似的功能,只需在JavaScript中。 jQuery庫是允許的。來自PHP的urlencode()在JavaScript中?
基本上,我需要對字符串進行編碼,然後用JavaScript將用戶重定向到另一個頁面。
有沒有功能比較匹配urlencode()
,但有一個相當相當於rawurlencode()
:encodeURIComponent()
。
用法:var encoded = encodeURIComponent(str);
你可以在這裏找到一個參考:從http://locutus.io/php/url/urlencode/
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeURIComponent
encodeURIComponent方法()
http://www.w3schools.com/jsref/jsref_encodeURIComponent.asp
看一看phpjs.org如果你正在尋找一個JS的功能等同於PHP:
http://phpjs.org/functions/urlencode:573
在這裏,您可以使用encodeURIComponent()
(帶一些修改)。
嘗試進行urlencode。 我已經測試過它在幾種情況下的工作。