반응형

[자바스크립트] escape() 함수의 뜻과 간단예제


escape() 함수는 ISO LATIN-1 문자를 %16진수의 ASCII 아스키코드값으로 변환하여 되돌려주는 함수이다.

다음의 예를 살펴보자.


예를 들어 escape("%")는 문자 "%"의 16진수 값 %25를 리턴한다.




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
<!DOCTYPE html>
 
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <h2>escape 함수를 이용한 예제</h2>
        <script>
            var str1, str2, str3
            str1 = "^"
            str2 = "$"
            str3 = "A"
 
            document.write("<h2>"+"문자1 = "+str1)
            document.write("<h2>"+"결과 > "+escape(str1)+"</h2><br>")
 
            document.write("<h2>"+"문자2 = "+str2)
            document.write("<h2>"+"결과 > "+escape(str2)+"</h2><br>")
 
            document.write("<h2>"+"문자3 = "+str3)
            document.write("<h2>"+"결과 > "+escape(str3)+"</h2><br>")
            document.write("ISO LATIN-1 문자만 가능")
        </script>
    </body>
</html>
 
cs







반응형
Posted by 제3인생자
l