以下是封装js及调用示例
https://files.cnblogs.com/szyicol/PCASClass.rar
以下是压缩和解压缩代码
<html>
<head>
<script src='PCASClass.js'></script>
</head>
<body>
<input type=button onclick=encodes() value=压缩> <input type=button onclick=decodes() value=解压>
<textarea id="ttt" rows=35 cols=120></textarea>
<script>
<!--
PCAD=PCAD.replace("--请选择省份--$--请选择城市--,--请选择地区--#","")
document.getElementById("ttt").value=PCAD
function decodes(){
PCAD=document.getElementById("ttt").value
for(i=0;i<PCAStore.length;i=i+2)PCAD=PCAD.replace(RegExp(PCAStore.substr(i,1),"g"),PCAStore.substr(i+1,1));
for(i=0;i<PCAStead.length;i=i+2)PCAD=PCAD.replace(RegExp(PCAStead[i],"g"),PCAStead[i+1]);
document.getElementById("ttt").value=PCAD
}
function encodes(){
PCAD=document.getElementById("ttt").value
for(i=0;i<PCAStead.length;i=i+2)PCAD=PCAD.replace(RegExp(PCAStead[i+1].replace(/([|$])/,"\\$1"),"g"),PCAStead[i].replace("\\",""));
for(i=0;i<PCAStore.length;i=i+2)PCAD=PCAD.replace(RegExp(PCAStore.substr(i+1,1),"g"),PCAStore.substr(i,1));
document.getElementById("ttt").value=PCAD
}
//-->
</script>
</body>
<head>
<script src='PCASClass.js'></script>
</head>
<body>
<input type=button onclick=encodes() value=压缩> <input type=button onclick=decodes() value=解压>
<textarea id="ttt" rows=35 cols=120></textarea>
<script>
<!--
PCAD=PCAD.replace("--请选择省份--$--请选择城市--,--请选择地区--#","")
document.getElementById("ttt").value=PCAD
function decodes(){
PCAD=document.getElementById("ttt").value
for(i=0;i<PCAStore.length;i=i+2)PCAD=PCAD.replace(RegExp(PCAStore.substr(i,1),"g"),PCAStore.substr(i+1,1));
for(i=0;i<PCAStead.length;i=i+2)PCAD=PCAD.replace(RegExp(PCAStead[i],"g"),PCAStead[i+1]);
document.getElementById("ttt").value=PCAD
}
function encodes(){
PCAD=document.getElementById("ttt").value
for(i=0;i<PCAStead.length;i=i+2)PCAD=PCAD.replace(RegExp(PCAStead[i+1].replace(/([|$])/,"\\$1"),"g"),PCAStead[i].replace("\\",""));
for(i=0;i<PCAStore.length;i=i+2)PCAD=PCAD.replace(RegExp(PCAStore.substr(i+1,1),"g"),PCAStore.substr(i,1));
document.getElementById("ttt").value=PCAD
}
//-->
</script>
</body>