當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


JavaScript unescape()用法及代碼示例

如果我們有一個使用 escape() 函數編碼的編碼數據,並且我們需要實際數據,在這種情況下 - 我們使用 unescape() 函數。這也是 JavaScript 中的一個預定義函數,它返回使用 escape() 函數編碼的解碼數據。

例:

<html>
<head>
<title>JavaScipt Example</title>
</head>

<body>
    <script>
        //Actual string
        str1 = "Hello world!";
        //encoded string
        str2 = escape(str1);
                
        document.write("Actual string is:" + str1);
        document.write("<br>");
        document.write("Encoded string is:" + str2);
        document.write("<br>");		
        //decoding the string
        str3 = unescape(str2);
        document.write("Decoded string is:" + str3);
        document.write("<br>");				

        //Actual string
        str1 = "email id:[email protected]";
        //encoded string
        str2 = escape(str1);
                
        document.write("Actual string is:" + str1);
        document.write("<br>");
        document.write("Encoded string is:" + str2);
        document.write("<br>");		
        //decoding the string
        str3 = unescape(str2);
        document.write("Decoded string is:" + str3);
        document.write("<br>");
    </script>
</body>
</html>

輸出

Actual string is:Hello world!
Encoded string is:Hello%20world%21
Decoded string is:Hello world!
Actual string is:email id:[email protected]
Encoded string is:email%20id%3A%[email protected]
Decoded string is:email id:[email protected]



相關用法


注:本文由純淨天空篩選整理自 unescape() function with example in JavaScript。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。