簡體   English   中英

轉義字符串等於JavaScript中的特殊字符

[英]Escape String equal special characters in JavaScript

我在JavaScript中有一個字符串:

ghi chú đặc biệt (!@#$%^&*) ngày 06/11/2018

如何在Java中將其轉義並解析為URL? 我嘗試使用:

encodeURIComponent(url);

但是我只是得到這個字符串:ghichúđặcbiệt(!@我該如何解決它,謝謝

應該簡單明了

 var uri = "ghi chú đặc biệt (!@#$%^&*) ngày 06/11/2018"; var res = encodeURIComponent(uri); console.log (res) 

請參閱-https: //www.w3schools.com/jsref/tryit.asp?filename=tryjsref_encodeuricomponent

您可以使用encodeURIComponent()和decodeURIComponent()對URL進行編碼,然后對其進行解碼。

 var url="ghi chú đặc biệt (!@#$%^&*) ngày 06/11/2018"; var encoded = encodeURIComponent(url); var decoded = decodeURIComponent(encoded) console.log(`Encoded url ${encoded}`); console.log(`Decoded url ${decoded}`); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM