Home >Web Front-end >JS Tutorial >How to convert url into Chinese characters in javascript
In javascript, you can use the unescape() function, decodeURIComponent() function and decodeURI() function to convert url into Chinese characters.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
Convert to url format | Convert to Chinese characters |
---|---|
escape(key) | unescape(key) |
encodeURI(key) | decodeURI(key) |
encodeURIComponent(key) | decodeURIComponent(key) |
The most commonly used one should be encodeURIComponent, which It is a URL encoding that converts special characters such as Chinese and Korean into UTF-8 format. Therefore, if you need to use encodeURIComponent to pass parameters to the background, you need background decoding to support UTF-8 (the encoding method in the form is the same as the encoding method of the current page).
escape does not encode 69 characters: *, ,-,.,/,@,_,0-9,a-z,A-Z
.
encodeURI has 82 non-encoded characters: !, #, $, &, ', (,), *, ,,,-,.,/,:,;,=,?, @,_,~,0-9,a-z,A-Z
.
encodeURIComponent has 71 unencoded characters: !, ', (,), *, -, ., _, ~, 0-9, a-z, A-Z
.
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How to convert url into Chinese characters in javascript. For more information, please follow other related articles on the PHP Chinese website!