码迷,mamicode.com
首页 > 其他好文 > 详细

字符转码

时间:2015-07-25 01:37:06      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>deom</title>
<script>
window.onload=function(){
var oText1 =document.getElementById(‘text1‘);
var oText2 =document.getElementById(‘text2‘);
var oBtn1 =document.getElementById(‘but1‘);
var oBtn2 =document.getElementById(‘but2‘);
//加密
oBtn1.onclick=function(){
var str =oText1.value;
var arr=[];
for(var i=0; i<str.length;i++){
var code =str.charCodeAt(i)+3;
arr.push(String.fromCharCode(code))
}
oText2.value =arr.join(‘‘);
}
//解密
oBtn2.onclick=function(){
var str =‘‘;
for(var i=0; i<oText2.value.length;i++){
str += String.fromCharCode(oText2.value.charCodeAt(i)-3)
}
oText1.value =str;
}
}
</script>
</head>
<body>
<textarea id=‘text1‘ col=‘20‘ row=‘50‘></textarea><br/>
<button id="but1">加密</button>
<button id="but2">解密</button><br/>
<textarea id=‘text2‘ col=‘20‘ row=‘50‘></textarea>
</body>
</html>

字符转码

标签:

原文地址:http://www.cnblogs.com/heboliufengjie/p/4675080.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!