zoukankan
html css js c++ java
URL编码反编码
<!
DOCTYPE html PUBLIC
"
-//W3C//DTD XHTML 1.0 Transitional//EN
"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
"
>
<
html xmlns
=
"
http://www.w3.org/1999/xhtml
"
>
<
head
>
<
meta http
-
equiv
=
"
Content-Type
"
content
=
"
text/html; charset=gb2312
"
/>
<
title
>
无标题文档
</
title
>
<
script type
=
"
text/javascript
"
>
function
doCode(deCode)
{
var
txt1
=
document.getElementById(
"
txt1
"
);
var
txt2
=
document.getElementById(
"
txt2
"
);
if
(deCode)
{
txt2.value
=
urlDecode(txt1.value);
}
else
{
txt2.value
=
urlEncode(txt1.value);
}
}
function
urlDecode(str)
{
if
(
"
undefined
"
==
typeof
decodeURIComponent)
{
return
unescape(str).replace(
/
\
+/
g, ' ').replace(
/%
2B
/
g,'
+
');
}
else
{
/**/
/*
just use my self decode script
*/
/**/
/*
return decodeURIComponent(str.replace(/\+/g, ' ').replace(/%2B/g,'+'));
*/
return
unescape(str).replace(
/
\
+/
g, ' ').replace(
/%
2B
/
g,'
+
');
}
}
function
urlEncode(str)
{
var
i,c,ret
=
""
,strSpecial
=
"
!\
"
#$
%&
'()
*+
,
/
:;
<=>?
@[\]
^
`
{
|
}
~%
"
;
for(i=0;i<str.length;i++)
{
c=str.charAt(i);
if(c==
"
"
)
ret+=
"
+
"
;
else if(strSpecial.indexOf(c)!=-1)
ret+=
"
%
"
+str.charCodeAt(i).toString(16);
else
ret+=c;
}
return ret;
};
</script>
</head>
<body>
<div id=
"
output
"
>
Source:<br />
<textarea name=
"
txt1
"
cols=
"
52
"
rows=
"
12
"
></textarea><br />
Destination:<br />
<textarea name=
"
txt2
"
cols=
"
52
"
rows=
"
12
"
></textarea><br />
<input name=
"
Decode
"
type=
"
button
"
value=
"
Decode
"
onclick=
"
doCode(
true
);
"
/>
<input name=
"
Encode
"
type=
"
button
"
value=
"
Encode
"
onclick=
"
doCode(
false
);
"
/>
</div>
</body>
</html>
查看全文
相关阅读:
python关于字典如何格式化地写入文件之中
关于python如何安装和配置chromedriver以及一些相关问题
python编码的原理以及写入文件中乱码的原因
json到底是什么??????
scrapy框架Request函数callback参数为什么是self.parse而不是self.parse( )
scrapy框架xpath的几点说明
python基于scrapy框架的反爬虫机制破解之User-Agent伪装
HTML,CSS,JavaScript,json,xml之间的关系
scrapy框架在未登录模式下爬取文本,文件和图片的几点收获
scrapy爬虫提取网页链接的两种方法以及构造HtmlResponse对象的方式
原文地址:https://www.cnblogs.com/afxcn/p/725916.html
最新文章
[转] 漫画:什么是 CAS 机制?
[转] RabbitMQ 消息如何保证100%的投递成功
[转] 探讨一下实现幂等性的几种方式
[转] 消息服务中如何确保消息至少被消费一次
[转] 谈谈mq消息消费的2种方式
[转] 聊聊业务系统中投递消息到mq的几种方式
[转] 聊聊mq的使用场景
JDBC-事务
Spring 注解 @Controller @RestController @Service @Repository @Component 源码对比
[转] 什么是Solr,它能为我们解决什么问题,怎么用?
热门文章
ActiveMQ客户端Apache.NMS从.net 4.0移植到.net standard 2.0
升级微服务架构5:API网关
升级微服务架构4:断路器
升级微服务架构3:服务发现及服务相互调用
升级微服务架构2:服务注册
升级微服务架构1:搭建Eureka Server服务中心
升级微服务架构0:技术选型
没使用Spring Cloud的版本管理导致Eureka服务无法注册到Eureka服务注册中心
win10家庭版启用远程桌面
Fiddler无法抓取web项目中的http请求解决方案
Copyright © 2011-2022 走看看