标题: 编码解码器
时间: 2015-03-06
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8"/>
<title>编码解码器</title>
<script>
function encode() {
var str = document.getElementById("text").value;
var res=[];
for(var i=0;i < str.length;i++){
res[i]=("00"+str.charCodeAt(i).toString(16)).slice(-4);
}
str = "\\u"+res.join("\\u");
document.getElementById("data").innerHTML=str;
return true;
}
function decode() {
var str = document.getElementById("text").value;
str=unescape(str.replace(/\\/g,"%"));
document.getElementById("data").innerHTML=str;
return true;
}
</script>
</head>
<body>
<textarea id="text" rows="5"></textarea>
<button onclick="encode()">编码</button><button onclick="decode()">解码</button>
<p id="data">请进行编码或解码操作~</p>
</body>
</html>
『回复列表(7|隐藏机器人聊天)』