{"id":759,"date":"2012-08-30T11:22:51","date_gmt":"2012-08-30T03:22:51","guid":{"rendered":"http:\/\/www.youthtribe.com\/?p=759"},"modified":"2012-08-30T11:22:51","modified_gmt":"2012-08-30T03:22:51","slug":"javascript%e4%b8%8b%e7%9a%84urlencode%e5%ba%94%e7%94%a8-%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"http:\/\/www.youthtribe.com\/archives\/759","title":{"rendered":"javascript\u4e0b\u7684urlencode\u5e94\u7528-\u51fd\u6570"},"content":{"rendered":"
<script language=”vbscript”>
\nFunction str2asc(strstr)
\nstr2asc = hex(asc(strstr))
\nEnd Function
\nFunction asc2str(ascasc)
\nasc2str = chr(ascasc)
\nEnd Function
\n<\/script>
\n<script language=”javascript” type=”text\/javascript”>
\nfunction UrlEncode(str){
\n\u00a0\u00a0 var ret=””;
\n\u00a0\u00a0 var strSpecial=”!\\”#$%&'()*+,\/:;<=>?[]^`{|}~%”;
\n\u00a0\u00a0 for(var i=0;i<str.length;i++){
\n\u00a0\u00a0 var chr = str.charAt(i);
\n\u00a0\u00a0\u00a0\u00a0 var c=str2asc(chr);
\n\u00a0\u00a0\u00a0\u00a0 if(parseInt(“0x”+c) > 0x7f){
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ret+=”%”+c.slice(0,2)+”%”+c.slice(-2);
\n\u00a0\u00a0\u00a0\u00a0 }else{
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if(chr==” “)
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ret+=”+”;
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 else if(strSpecial.indexOf(chr)!=-1)
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ret+=”%”+c.toString(16);
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 else
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ret+=chr;
\n\u00a0\u00a0\u00a0\u00a0 }
\n\u00a0\u00a0 }
\n\u00a0\u00a0 return ret;
\n}
\n<\/script><\/p><\/blockquote>\n<\/p>\n
\u7528\u8fd9\u6837\u7684\u529e\u6cd5\u8c03\u7528\uff1a<\/p>\n
<script language=”javascript” type=”text\/javascript”>
\nalert(UrlEncode(“\u9752\u6625\u90e8\u843d”));
\n<\/script><\/p>\njavascript\u4e0b\u7684urlencode\u5e94\u7528-\u51fd\u6570<\/p>\n","protected":false},"excerpt":{"rendered":"
<script language=”vbscript”> Function str2asc(strstr) str2asc = hex(asc(strstr)) End Function Function asc2str(ascasc) asc2str = chr(ascasc) End Function <\/script> <script language=”javascript” type=”text\/javascript”> function UrlEncode(str){ \u00a0\u00a0 <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,9],"tags":[],"_links":{"self":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/759"}],"collection":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/comments?post=759"}],"version-history":[{"count":2,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/759\/revisions"}],"predecessor-version":[{"id":761,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/759\/revisions\/761"}],"wp:attachment":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/media?parent=759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/categories?post=759"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/tags?post=759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}