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>
查看全文
相关阅读:
如何修改mysql root密码
【STL】list基础(转)
时间控制timer settimeout setinterval
刷新ArrayCollection的显示控件
需要科普的网站
flex 拖拽数据
常用的资源网站
as3 性能优化
对象池
Bitmap与Bitmapdata
原文地址:https://www.cnblogs.com/afxcn/p/725916.html
最新文章
Android 开发入门系列之开发环境搭建
如何判断android 手机支持哪些传感器
ubuntu su进入root权限
添加本地通知(UILocalNotification)以及添加系统组件滚动视图(UIScrollView)
ios UIButton的点击与松开事件处理
iPhone的九宫格实现代码
ios singleton单例模式及代码
IOS可以拖动的UIButton
ObjectiveC 属性特性(assign , retain , copy , readonly , readwrite , atomic , nonatomic)
iPhone多国语言版本
热门文章
ObjectiveC内存管理知识总结
UIScrollView代码实现循环滚动
【转】应届生学C好还是学JAVA好,做什么更挣钱
[置顶] Java程序员们读什么书决定了对未来职业方向的选择
[置顶] 计算机相关书籍推荐(持续更新)
转:牛人发的评论
c++面试题之内存分配
Ubuntu常用命令与技巧
win7中chm无法显示
eclipse使用技巧
Copyright © 2011-2022 走看看