JavaScript escape()函数

下面是一个例子 escape()函数 .

null
  • 例子:

    <script>
    // Special character encoded with
    // escape function
    document.write(escape( "Geeks for Geeks!!!" ));
    document.write( "<br>" );
    // Print encoded string using escape() function
    // Also include exceptions i.e. @ and .
    document.write(escape( "To contribute articles contact" +
    " us at review-team@geeksforgeeks.org" ));
    </script>

    
    

  • 输出:
    Geeks%20for%20Geeks%21%21%21
    To%20contribute%20articles%20contact%20us%20atcontribute
    @geeksforgeeks.org 

这个 escape()函数 将字符串作为参数并对其进行编码,以便可以将其传输到任何支持ASCII字符的网络中的任何计算机。

语法:

escape(string)

参数: 此函数接受一个参数,如上所述,如下所述:

  • 字符串: 此参数保存将被编码的字符串。

返回值: 此函数返回一个编码字符串。

注: 此函数仅对特殊字符进行编码,此函数是经过擦洗的。 例外情况: @ – + . / * _

以上功能的更多示例代码如下:

项目1:

<script>
// Special character encoded with
// escape function
document.write(escape( "Geeks for Geeks!!!" ));
document.write( "<br>" );
// Print encoded string using escape() function
// Also include exceptions i.e. @ and .
document.write(escape( "A Computer Science Portal" ));
</script>


输出:

Geeks%20for%20Geeks%21%21%21
A%20Computer%20Science%20Portal

项目2:

<script>
// Special character encoded with
// escape function
document.write(escape( "GeeksforGeeks" ));
document.write( "<br>" );
// Print encoded string using escape() function
// Also include exceptions i.e. @ and .
document.write(escape( "A#Computer-Science" +
"%Portal@for*Geeks" ));
</script>


输出:

GeeksforGeeks
A%23Computer-Science%25Portal@for*Geeks

支持的浏览器:

  • 谷歌Chrome 1及以上版本
  • Internet Explorer 3及以上版本
  • 边缘12及以上
  • Mozilla Firefox 1及以上版本
  • Safari 1及以上
  • 歌剧3及以上
© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享