一、
<script language="Javascript">
alert(escape("我是汉字"));
alert(unescape("%u6211%u662f%u6c49%u5b57"));
</script>
二、
<script type="text/javascript">
var s='我是汉字',t='';
for(i=0;i<s.length;i++){t+='\\u'+s.charCodeAt(i).toString(16);}
alert(t);
var t=eval('\''+t.replace(/\\\\/g, '\\')+'\'');
alert(t);
</script>
三、
<script Language=Javascript>
var classObj={
ToUnicode:function(str) {return escape(str).replace(/%/g,"\\").toLowerCase();},
UnUnicode:function(str){return unescape(str.replace(/\\/g, "%"));}
}
alert(classObj.ToUnicode("必须输入"));
alert(classObj.UnUnicode("\u5fc5\u987b\u8f93\u5165"));
</script>
四、
<script language="Javascript">
var classObj={
ToUnicode:function(str) {return escape(str).replace(/%/g,"\\").toLowerCase();},
UnUnicode:function(str){return unescape(str.replace(/\\/g, "%"));},
copyingTxt:function(str){document.getElementById(str).select(); document.execCommand("Copy");}
}
</script>
<textarea id="codes" style="width:500px;height:300px"></textarea><br><br>
<input type="button" value="Unicode加密" onclick="javascript:codes.value=classObj.ToUnicode(codes.value)" />
<input type="button" value="Unicode解密" onclick="javascript:codes.value=classObj.UnUnicode(codes.value)" />
<input type="button" value="复制上面文本" onclick="javascript:classObj.copyingTxt('codes')" />
<input type="button" value="清空上面内容" onclick="javascript:codes.value=''" />