使用JavaScript對(duì)網(wǎng)頁(yè)中的數(shù)據(jù)進(jìn)行加密,具體方法如下:
<script type="text/javascript">
#加密
function encode(content){
var $ ="";
for(var u=0; u < content.length; u++)
{
var r = content.charCodeAt(u);
$+= String.fromCharCode(r+2);
}
return $;
};
#解密
function decode(content){
var $ ="";
for(var u=0; u < content.length; u++)
{
var r = content.charCodeAt(u);
$+= String.fromCharCode(r-2);
}
return $;
};
var str = "hello";
document.write(encode(str) +"<br>");
document.write(decode(encode(str)));
</script>