js JavaScript encodeURIComponent () function, URL encoding conversion, esca

encodeURIComponent () The definition and use of

encodeURIComponent () function can be the string encoded as a URI component. 
Syntax

encodeURIComponent (URIstring)

Parameter Description 
URIstring necessary. A string containing components or other URI-encoded text. 
Return value

URIstring a copy of some of the characters will be the hexadecimal escape sequence to replace. 
Description

This method will not ASCII encoding of letters and numbers, or punctuation these ASCII encoding: - _.! ~ * '().

Other characters (such as those used to separate :;/?:@&=+$,# components punctuation URI), by one or more hexadecimal escape sequence replacement. 
Tips and Notes

Tip: Please note encodeURIComponent () function and encodeURI () function of the difference, which assumes that its parameter is the URI part (such as agreements, host name, path or query string). Therefore encodeURIComponent () function to escape the various parts of URI used to separate punctuation. 
Examples

In this case, we will use encodeURIComponent () to encode 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>

Output:

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

escape () method: 
ISO Latin character set used to encode the specified string. All the space characters, punctuation, special characters, as well as other non-ASCII characters will be converted into% xx character encoding format (xx equal to the characters in the character set encoding table inside the 16-band digital). For example, at the corresponding code space is% 20. On the contrary unescape methods. This method will not be encoded characters: @ * / +

encodeURI () method: 
The URI string using UTF-8 encoding format into a format string escape. This method will not be encoded characters:! @ # $ & * () =: /;? + '

encodeURIComponent () method: 
The URI string using UTF-8 encoding format into a format string escape. And encodeURI () compared to this method will encode more characters, such as / etc characters. Therefore, if the URI string which contains several parts, then this method can not be used to encode, or / characters encoded URL will be displayed after the error. This method will not be encoded characters:! * ()

Black hair: http://heisetoufa.javaeye.com/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值