您的位置:首页 > 编程语言

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

2009-05-15 15:18 357 查看
<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: