加密输入内容

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>

<body>

<input type="text" />
<input type="button" value="加密" />
<div id="div1">加密...</div>

<script>
var aInp = document.getElementsByTagName('input');
var oDiv = document.getElementById('div1');

aInp[1].onclick = function () {   
    var str = aInp[0].value;            // 获取输入的字符串
    var str1 = '';
    for ( var i=0; i<str.length; i++ ) {   //遍历输入的字符串里的所有字符
        str1 += String.fromCharCode(str.charCodeAt(i)-520);   
//给字符串里的所有字符的编码都减去520(可以是任意自己设定的数字),然后再把减去520后的编码转换成新的字符串,一个个拼接起来 } oDiv.innerHTML
= str1; //把新的字符串显示在div中 }; </script> </body> </html>

 

posted @ 2017-03-23 18:25  念念念不忘  阅读(152)  评论(0)    收藏  举报