Julius's profile◎背包驿站☆BlogListsGuestbook Tools Help

Blog


    July 24

    JS中的escape() & encodeURI() & encodeURIComponent()

    escape()
    返回一个可在所有计算机上读取的编码 String 对象。
    程序代码 function escape(charString : String) : String
    参数 charString 必选。要编码的任何 String 对象或文本。
    备注 escape 方法返回一个包含 charstring 内容的字符串值(Unicode 格式)。所有空格、标点、重音符号以及任何其他非 ASCII 字符都用 %xx 编码替换,其中 xx 等于表示该字符的十六进制数。例如,空格返回为“%20”。字符值大于 255 的字符以 %uxxxx 格式存储。
    注意  escape 方法不能用来对“统一资源标识符”(URI) 进行编码。对其编码应使用 encodeURI 和 encodeURIComponent 方法。

    encodeURI()
    返回编码为有效的统一资源标识符 (URI) 的字符串。
    程序代码 function encodeURI(URIString : String) : String
    参数 URIString 必选。表示编码 URI 的字符串。
    备注 encodeURI 方法返回一个已编码的 URI。如果将编码结果传递给 decodeURI,则将返回初始的字符串。encodeURI 不对下列字符进行编码:“:”、“/”、“;”和“?”。请使用 encodeURIComponent 对这些字符进行编码。
    escape() 只是为 ASCII字符 做转换工作,转换成的 %unnnn 形式的码,如果要用更多的字符如 UTF-8字符库 就一定要用 encodeURIComponent() 或 encodeURI() 转换才可以成 %nn%nn 这的码才可以。

    encodeURIComponent()
    返回编码为统一资源标识符 (URI) 的有效组件的字符串。
    程序代码 function encodeURIComponent(encodedURIString : String) : String
    参数 encodedURIString 必选。表示编码 URI 组件的字符串。
    备注 encodeURIComponent 方法返回一个已编码的 URI。如果将编码结果传递给 decodeURIComponent,则将返回初始的字符串。因为 encodeURIComponent 方法将对所有字符编码,请注意,如果该字符串代表一个路径,例如 /folder1/folder2/default.html,则其中的斜杠也将被编码,这样,当该字符串作为请求发送到 Web 服务器时它将是无效的。如果字符串中包含多个 URI 组件,请使用 encodeURI 方法进行编码。

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://drymarsh.spaces.live.com/blog/cns!4057E918F85F717D!472.trak
    Weblogs that reference this entry
    • None