当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。