Unicode汉字转码特效代码下载地址

来源: 代码笔记   发布时间:2016-07-06 06:42:43

<script language="javascript" type="text/javascript"> var oSource = document.getElementById("source"); var oShow2 = document.getElementById("show2"); var oTt = document.getElementById("tt"); function action(pChoice){ switch(pChoice){ case "CONVERT_FMT1": oShow2.value = ascii(oSource.value); break; case "CONVERT_FMT2": oShow2.value = unicode(oSource.value); break; case "RECONVERT": oShow2.value = reconvert(oSource.value); break; } } function ascii(str){ return str.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\&#x$2;")}); } function unicode(str){ return str.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\\u$2")}); } function reconvert(str){ str = str.replace(/(\\u)(\w{4})/gi,function($0){ return (String.fromCharCode(parseInt((escape($0).replace(/(%5Cu)(\w{4})/g,"$2")),16))); }); str = str.replace(/(&#x)(\w{4});/gi,function($0){ return String.fromCharCode(parseInt(escape($0).replace(/(%26%23x)(\w{4})(%3B)/g,"$2"),16)); }); return str; } </script>