Fastest way to encode cyrillic letters for url

前端 未结 2 1043
旧时难觅i
旧时难觅i 2021-02-07 10:33

If you copy the link below into the browser

http://be.wikipedia.org/wiki/Беларусь 

it will show the Wiki article. But once you want to copy th

2条回答
  •  逝去的感伤
    2021-02-07 11:19

    The function you're searching for is encodeURIComponent.

    encodeURIComponent("Беларусь");
    // returns "%D0%91%D0%B5%D0%BB%D0%B0%D1%80%D1%83%D1%81%D1%8C"
    

    Its counterpart is decodeURIComponent which reverses this process.

    decodeURIComponent("%D0%91%D0%B5%D0%BB%D0%B0%D1%80%D1%83%D1%81%D1%8C");
    // returns "Беларусь"
    

提交回复
热议问题