JavaScript:gb2312转unicode -- &#X形式

<html>
<head>
<title>gb2312 unicode转换工具</title>
<div align=center>
<center>
<table border=0 cellpadding=0 cellspacing=0 style="border-collapse: collapse" width=600 id=AutoNumber1 height=26>
  <tr>
    <td width=100% height=26>
    <p align=center><font face=黑体 size=5 color=#FF0000>unicode  转换工具</font></p>
    <p>使用方法:</p>
    <p>  在下面的文本框中输入中文文字,按“转化”,即可将其转化为unicode字符。</p>
    <p>  再按“还原”,即可将其还原为简体中文。</td>
  </tr>
</table>
</center>
</div>
<p align=center>
<textarea cols=82 rows=10 id=code>
</textarea> </p>
<p align=center>

<input type=button onclick=encode(code,this) value=转化>
<script>
var mode="zhuan";
function encode(obj,btn){
   if(mode=="zhuan"){
       obj.value=obj.value.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"&#x$2;")});
       btn.value="还原";
       mode="huan";
   }else{
       obj.value=unescape(obj.value.replace(/&#x/g,'%u').replace(/;/g,''));
       btn.value="转化";
       mode="zhuan";
   }
}
</script></p>
posted @   meil  阅读(3366)  评论(2编辑  收藏  举报
编辑推荐:
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
阅读排行:
· 2分钟学会 DeepSeek API,竟然比官方更好用!
· .NET 使用 DeepSeek R1 开发智能 AI 客户端
· DeepSeek本地性能调优
· autohue.js:让你的图片和背景融为一体,绝了!
· 10亿数据,如何做迁移?
点击右上角即可分享
微信分享提示