编码解码器

把“我爱你”编码成“\u6211\u7231\u4f60”
把“\u6211\u7231\u4f60”解码成“我爱你”
我也不知道这叫什么,所以直接叫做编码解码器
临时演示:http://www.ll00.cn/decode.html
<!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|隐藏机器人聊天)
添加新回复
回复需要登录