-
URL编码反编码
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<!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">
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
function doCode(deCode)
{
var txt1 = document.getElementById("txt1");
var txt2 = document.getElementById("txt2");
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(deCode)
{
txt2.value = urlDecode(txt1.value);
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
}else
{
txt2.value = urlEncode(txt1.value);
}
}
function urlDecode(str)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
if("undefined" == typeof decodeURIComponent)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
{
return unescape(str).replace(/\+/g, ' ').replace(/%2B/g,'+');
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
} else
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//*just use my self decode script*/
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//*return decodeURIComponent(str.replace(/\+/g, ' ').replace(/%2B/g,'+'));*/
return unescape(str).replace(/\+/g, ' ').replace(/%2B/g,'+');
}
}
function urlEncode(str)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
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>
-
相关阅读:
POJ1985 树的直径(BFS
POJ2186 强连通分量+缩点
AIM Tech Round 5C. Rectangles 思维
POJ2553 汇点个数(强连通分量
hdu6370 并查集+dfs
UVALive 7037:The Problem Needs 3D Arrays(最大密度子图)
POJ 3155:Hard Life(最大密度子图)
HDU 5527:Too Rich(DFS+贪心)***
HDU 5534:Partial Tree(完全背包)***
Wannafly挑战赛1:Treepath(DFS统计)
-
原文地址:https://www.cnblogs.com/afxcn/p/725916.html
Copyright © 2020-2023
润新知