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>
查看全文
相关阅读:
Javascript的私有变量和方法、共有变量和方法以及特权方法、构造器、静态共有属性和静态共有方法
Spring4整合Hibernate4出现的错误的解决
Javascript类的创建
Kettle学习总结(一)
Kettle Excel导入数据到数据库
Python 爬虫 2 (转)
Js仿腾讯微博效果
飘雪效果
列表获取对应图片
飞入购物车
原文地址:https://www.cnblogs.com/afxcn/p/725916.html
最新文章
linux命令,压缩打包(gzip,zcat,bzip2,bzcat,tar)
linux命令,文件与目录(cp,pwd,mkdir,rmdir;ls,cp,rm,mv,basename,dirname;cat,tac,more,less,head,tail,touch,umask,chattr,file,which,locate,find)
linux命令,改变文件属性权限(chgrp,chown,chmod)
linux命令,关机、重启(shutdown,reboot,halt,poweroff)
linux命令,date,cal,bc,tab,ctrl+c,ctrl+d,man
Highcharts只显示点不显示线的问题
Highcharts动态画曲线
Resharp Alt+Enter找回
面试问题总结
MVVM模式下 触发器多条件判断
热门文章
Caliburn框架中二级Menu无法调用ViewModel方法
WPF中Textbox长度限制
WPF 根据绑定值设置DataGrid行背景色
查找离当前日期30天内的记录
SQL语句将表中数据导入到另一个数据库表中
【Javascript设计模式】第四课 幽灵工厂——抽象工厂模式
【Javascript设计模式】第三课 工厂方法模式
【Javascript设计模式】第二课 神奇的魔术师——简单工厂模式
GitHub超详细图文攻略
【Javascript设计模式】第一课 Javascript中的继承
Copyright © 2011-2022 走看看