中文转换Ascii和Unicode编码小工具-代码

来源:互联网 发布:淘宝去凑单如何设置 编辑:程序博客网 时间:2024/05/29 21:29

<html>
 <head>
 <script>
 function encode2ascii(s,t){
  t.value="";
  var str=s.value;
  t.value=str.replace(/[^/u0000-/u00FF]/g,function($0){return escape($0).replace(/(%u)(/w{4})/gi,"//u$2")});
 }
 

 function encode2unicode(s,t){
  t.value="";
  var str=s.value;
  t.value=str.replace(/[^/u0000-/u00FF]/g,function($0){return escape($0).replace(/(%u)(/w{4})/gi,"&#x$2;")});
 }
 </script>
 </head>
 <body>
  源码:
  <br>
  <textarea  rows=5 id="source" style="WIDTH: 70%"></textarea>
  <p>
  <input type="button" onclick="encode2ascii(source,target)" value="转化Ascii编码">

  <input type="button" onclick="encode2unicode(source,target)" value="转化Unicode编码">
  <p>
  转换结果:
  <br>
  <textarea rows=5 id=target style="WIDTH:70%"></textarea>
 </body>
</html>

 

原创粉丝点击