语法

encodeURIComponent(URIstring)
参数 描述
URIstring 必需。一个字符串,含有 URI 组件或其他要编码的文本。

返回值

URIstring 的副本,其中的某些字符将被十六进制的转义序列进行替换。

说明

该方法不会对 ASCII 字母和数字进行编码,也不会对这些 ASCII 标点符号进行编码: - _ . ! ~ * ' ( ) 。

其他字符(比如 :;/?:@&=+$,# 这些用于分隔 URI 组件的标点符号),都是由一个或多个十六进制的转义序列替换的。

提示和注释

提示:请注意 encodeURIComponent() 函数 与 encodeURI() 函数的区别之处,前者假定它的参数是 URI 的一部分(比如协议、主机名、路径或查询字符串)。因此 encodeURIComponent() 函数将转义用于分隔 URI 各个部分的标点符号。

实例

在本例中,我们将使用 encodeURIComponent() 对 URI 进行编码:

<script type="text/javascript">

document.write(encodeURIComponent("http://www.w3school.com.cn"))
document.write("<br />")
document.write(encodeURIComponent("http://www.w3school.com.cn/p 1/"))
document.write("<br />")
document.write(encodeURIComponent(",/?:@&=+$#")) </script>

输出:

http%3A%2F%2Fwww.w3school.com.cn
http%3A%2F%2Fwww.w3school.com.cn%2Fp%201%2F
%2C%2F%3F%3A%40%26%3D%2B%24%23

encodeURIComponent() 函数可把字符串作为 URI 组件进行编码的更多相关文章

  1. JavaScript escape encodeURI encodeURIComponent() 函数

    总结一下: 1.encodeURI(),和encodeURIComponent()是对字符进行编码. 2.decodeURI(),和decodeURIComponent()是对相应编码过的字符进行解码 ...

  2. encodeURIComponent() 函数的使用

    说明:encodeURIComponent() 函数可把字符串作为 URI 组件进行编码. 维护项目中,遇到一个登录的问题:(用户的loginName为33195221,密码为147258369+), ...

  3. js中的encodeURIComponent()函数

    encodeURIComponent() 函数可把字符串作为 URI 组件进行编码. $scope.linktotheme = function () { if ($scope.curthemeid ...

  4. encodeURIComponent() 函数

    https://baike.baidu.com/item/encodeURIComponent() 函数/7418815?fr=aladdin encodeURIComponent() 函数[1] 作 ...

  5. escape,encodeURI,encodeURIComponent函数比较

    escape,encodeURI,encodeURIComponent函数比较 js对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数 ...

  6. JS中encodeURIComponent函数用php解码的代码

    JS中encodeURIComponent函数给中文编码后,如何用php解码?? 前提:编码前的中文可能是gbk,gb2312,utf-8等. 复制代码 代码如下: urldecode() iconv ...

  7. c#实现Javascript的encodeURIComponent()函数

    原文  c#实现Javascript的encodeURIComponent()函数 国内外各搜索引擎,均用JavaScript的encodeURIComponent()函数对搜索关键字进行编码,终于找 ...

  8. C/C++ Qt StringListModel 字符串列表映射组件

    StringListModel 字符串列表映射组件,该组件用于处理字符串与列表框组件中数据的转换,通常该组件会配合ListView组件一起使用,例如将ListView组件与Model模型绑定,当Lis ...

  9. MySQL中concat函数(连接字符串)

    MySQL中concat函数使用方法:CONCAT(str1,str2,…) 返回结果为连接参数产生的字符串.如有任何一个参数为NULL ,则返回值为 NULL. 注意:如果所有参数均为非二进制字符串 ...

随机推荐

  1. Spring security 知识笔记【内存角色授权】

    一.原有的配置文件中,增加注解@EnableGlobalMethodSecurity(prePostEnabled = true) 二.原有配置文件中,内存新建账号的时候添加角色 package El ...

  2. 关于Design Complier/Library Compiler的跌坑(坑爹)记录

    最近需要用DC做一些事,然后需要转库,中午偷个闲,特来记录一下中间的一些坎坷. 1.首先是要转库.我们只有.lib文件的格式,所以需要把.lib文件转换成.db格式.然后坑来了!!!DC2015及以后 ...

  3. copy running-config startup-config 与 copy startup-config running-config

    1.copy running-config startup-config 与 copy startup-config running-config 两者有什么不同???ANS:running-conf ...

  4. 苹果开发之App签名

    如果你的Apple ID账号(可使用邮箱来注册)为Apple developer类型的话,登录之后是看不到Certificates, Indentifiers & Profiles信息的 Ap ...

  5. json data转匿名对象C#

    using Newtonsoft.Json.Linq; 代码如下: static void Main(string[] args) { Console.WriteLine("Test 4.8 ...

  6. nginx 指向本地目录

    # 必须配置此目录 location /upload { root D:\\upload\\; rewrite break; }

  7. C# Thread was being aborted

    先重现问题 1.新建一个aspx页面项目,插入两个页面WebForm1.aspx,WebForm2.aspx, WebForm1代码修改如下 protected void Page_Load(obje ...

  8. cmd命令和linux命令的区别

    cmd命令和linux命令看起来很相似,都是在一个控制台输入一些特定的指令去完成一些特定的操作.可是用过的朋友就会发现这些指令是有很多不同的,可是到底有什么不同,要说又说不上来,所以要了解一下. cm ...

  9. KVM 学习笔记

    查看虚拟化环境 (1)查看虚拟机环境 (2)查看kvm模块支持 (3)查看虚拟工具版本 (4)查看网桥

  10. golang ----array and slice

    Go Slices: usage and internals Introduction Go's slice type provides a convenient and efficient mean ...