标签:style io ar os for on cti tt res
<p>
<textarea id="code11" style="width: 400px; height: 100px;" height="100"></textarea>
<br><br>
<input onclick="bianma()" type="button" value="编码"> <br><br>
<textarea id="code12" style="width: 400px; height: 100px;"></textarea>
</p>
<p>
<textarea id="code21" style="width: 400px; height: 100px;"></textarea>
<br><br>
<input onclick="jiema()" type="button" value="解码"><br><br>
<textarea id="code22" style="width: 400px; height: 100px;"></textarea>
</p>
<script>
var decToHex = function(str) {
var res=[];
for(var i=0;i < str.length;i++)
res[i]=("00"+str.charCodeAt(i).toString(16)).slice(-4);
return "\\u"+res.join("\\u");
}
var hexToDec = function(str) {
str=str.replace(/\\/g,"%");
return unescape(str);
}
var bianma=function(){
document.getElementById(‘code12‘).value=decToHex(document.getElementById(‘code11‘).value);
}
var jiema=function(){
document.getElementById(‘code22‘).value=hexToDec(document.getElementById(‘code21‘).value);
}
</script>
标签:style io ar os for on cti tt res
原文地址:http://www.cnblogs.com/dingyuanxin/p/4104437.html