urlencodeÔÚjsÖÐÔõôд
javascriptÖеÄurl±àÂ뽫ÌØÊâ×Ö·û£¨Èç¿Õ¸ñ£©×ª»»ÎªÊ®Áù½øÖƱàÂ룬ȷ±£Çå¾²´«Êäµ½webЧÀÍÆ÷¡£ÒªÁ죺ʹÓÃencodeuricomponent()º¯Êý£ºencodedstring = encodeuricomponent(originalstring)º¯Êý½«asciiÂë´óÓÚ255µÄ×Ö·ûת»»Îª%xxÊ®Áù½øÖƱàÂë¡£encodeuricomponent()²»»á±àÂëÐǺÅ(*)¡¢¾äºÅ(.)ºÍÏ»®Ïß(_)£¬ÐèÓÃencodeuri()±àÂëËùÓÐ×Ö·û¡£
JavaScriptÖеÄURL±àÂë
JavaScriptÖеÄURL±àÂëÓÃÓÚ½«ÌØÊâ×Ö·û£¨ÀýÈç¿Õ¸ñºÍ·ÇÓ¢Óï×Ö·û£©×ª»»ÎªÆäÊ®Áù½øÖƱàÂ룬ÒÔÈ·±£ËüÃÇ¿ÉÒÔÇå¾²µØ´«Êäµ½WebЧÀÍÆ÷¡£
ÔõÑùʹÓÃJavaScript¾ÙÐÐURL±àÂë
ʹÓÃJavaScript¾ÙÐÐURL±àÂëµÄ±ê×¼ÒªÁìÊÇʹÓÃencodeURIComponent()º¯Êý£º
let encodedString = encodeURIComponent(originalString);
µÇ¼ºó¸´ÖÆ
ÀýÈ磬Ҫ¶Ôº¬ÓпոñµÄ×Ö·û´®”Hello World”¾ÙÐÐURL±àÂ룺
let encodedString = encodeURIComponent("Hello World"); // "Hello%20World"
µÇ¼ºó¸´ÖÆ
encodeURIComponent()º¯ÊýµÄÊÂÇéÔÀí
encodeURIComponent()º¯Êý½«Ã¿¸öASCIIÂë´óÓÚ255µÄ×Ö·ûת»»Îª%xxÐÎʽµÄÊ®Áù½øÖƱàÂ룬ÆäÖÐxxÊǸÃ×Ö·ûµÄÊ®Áù½øÖÆÌåÏÖ¡£ÕâÈ·±£ÁËËùÓÐÌØÊâ×Ö·û¶¼¿ÉÒÔͨ¹ýHTTPÐÒéÇå¾²µØ´«Êä¡£
×¢ÖØÊÂÏî
encodeURIComponent()º¯Êý²»»á¶ÔijЩÌØÊâ×Ö·û¾ÙÐбàÂ룬ÈçÐǺÅ(*)¡¢¾äºÅ(.)ºÍÏ»®Ïß(_)¡£
ÔÚ¶Ô°üÀ¨·ÇÓ¢Óï×Ö·ûµÄ×Ö·û´®¾ÙÐÐURL±àÂëʱ£¬¿ÉÒÔʹÓÃencodeURI()º¯ÊýÀ´±àÂëÕû¸öURI£¬ÓÉÓÚËü»á±àÂëËùÓÐ×Ö·û£¬°üÀ¨±£´æ×Ö·û¡£
Çë×¢ÖØ£¬URL½âÂëͨ³£ÔÚЧÀÍÆ÷¶ËʹÓÃdecodeURIComponent()º¯Êý¾ÙÐС£
ÒÔÉϾÍÊÇurlencodeÔÚjsÖÐÔõôдµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡