인코딩 하려면 encodeURIComponent() 또는 encodeURI()가 필요한 문자열 디코딩 decodeURIComponent()가 필요한 문자열 또는 decodeURI() . 처음에는 escape()를 사용했습니다. 인코딩 문자열이지만 더 이상 사용되지 않으므로 이제 encodeURI()를 사용하고 있습니다. .
구문-1
encodeURIComponent(string);
구문-2
decodeURIComponent(string);
예시
다음 예에서는 처음에 문자열을 가져와 인코딩 합니다. encodeURI() 사용 나중에 디코딩 decodeURI() 사용 . 나중에 인코딩된 및 디코딩 결과가 출력에 표시되었습니다.
<html>
<body>
<p id = "encoding"></p>
<script>
var str = "Tutorix is the best e-learning platform";
var enc = encodeURI(str);
var dec = decodeURI(enc);
var res = "After encoding: " + enc + "
</br>" + "After Decoding: " + dec;
document.getElementById("encoding").innerHTML = res;
</script>
</body>
</html> 출력
After encoding: Tutorix%20is%20the%20best%20e-learning%20platform After Decoding: Tutorix is the best e-learning platform