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>
查看全文
相关阅读:
dwz 嵌套网页的搜索刷新问题
dwz 解决remote验证唯一时缓存问题。
dwz div 局部刷新
Oracle 递归查询子节点和父节点 函数方法
关于未能加载文件或程序集“System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或它的某一个依赖项的解决办法
CentOS7搭建vsftp服务器
Linux下 cmatrix的安装和使用(黑客屏保)
配置动态web服务(wsgi)
centos7 搭建discuz 全
Centos7 更换为阿里源
原文地址:https://www.cnblogs.com/afxcn/p/725916.html
最新文章
【Vue中的swiper轮播组件】
【原生js实现---图片懒加载代码】
【原生js实现一键回到顶部】
【JavaScript中typeof、toString、instanceof、constructor与in】
【详解面向对象、构造函数、原型与原型链、继承、封装】
重绘和回流----降低回流减少性能影响
【页面传值6种方式】- 【JSP 页面传值方法总结:4种】
【vue组件之间互相传值:父传子,子传父】
【Gulp自动化构建工具】
Koa 框架教程
热门文章
【依赖注入】
Angular--快捷命令操作
Angular生命周期
Ionic2
React .js框架的环境搭建
Salesforce 覆盖率SQL查询
Salesforce 批量更新user 密码
Salesforce
asp.net mvc单元测试
dwz 局部分页
Copyright © 2011-2022 走看看