出处找不到了,不好意思了原创老兄。
复制下列代码,保存为HTML文件即可。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>GB2312转UTF-8码</title>
<style type="text/css">
<!--
* {
font-family: Verdana, Arial, sans-serif;
font-size: 11px;
margin: 0;
}
input, textarea {
border-width: 1px;
}
body {
text-align: center;
}
#wrap {
width: 300px;
margin: 0 auto;
}
h1 {
margin: 10px 0;
}
-->
</style>
</head><body>
<div id="wrap">
<h1>GB2312 To UTF-8 转换器</h1>
<p><textarea name="textarea" cols="40" rows="10" id="code"></textarea></p>
<p> </p>
<p><input type=button οnclick=encode(code,this) value=" 转化为UTF-8 "></p>
<script type="text/javascript">
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="还原为GB2312";
mode="huan";
}else{
obj.value=unescape(obj.value.replace(/&#x/g,''%u'').replace(/;/g,''''));
btn.value=" 转化为UTF-8 ";
mode="zhuan";
}
}
</script>
</div>
</body>
</html>