<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Unicode编码转换工具</title>
<script type="text/javascript">
//ASCII 转换 Unicode
function AsciiToUnicode(){
if (document.getElementById("content").value==""){
alert("文本框中没有代码!");
return;
}
document.getElementById("result").value="";
for (var i=0;i<document.getElementById("content").value.length;i++){
result.value+="&#"+document.getElementById("content").value.charCodeAt(i)+";";
}
document.getElementById("content").focus();
}
//Unicode 转换 ASCII
function UnicodeToAscii(){
var code=document.getElementById("content").value.match(/&#(\d+);/g);
if (code==null){
alert("文本框中没有合法的Unicode代码!");
document.getElementById("content").focus();
return;
}
document.getElementById("result").value="";
for (var i=0;i<code.length;i++){
document.getElementById("result").value+=String.fromCharCode(code[i].replace(/[&#;]/g,""));
}
document.getElementById("content").focus();
}
function preview(){
var win=window.open();
win.document.open("text/html","replace");
win.document.writeln(document.getElementById("result").value);
win.document.close();
}
</script>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="1">
<tr>
<td height="50" colspan="2"><h1>Unicode编码转换工具</h1></td>
</tr>
<tr>
<td height="25" colspan="2">Unicode 转换 ASCII,ASCII 转换 Unicode</td>
</tr>
<tr>
<td width="50%"><textarea id="content" name="content" rows="20" cols="60"></textarea></td>
<td width="50%"><textarea id="result" name="result" rows="20" cols="60"></textarea></td>
</tr>
<tr>
<td height="30"><input name="button" type="button" value="ASCII 转换 Unicode↓"/>
<input name="button" type="button" value="Unicode 转换 ASCII↓"/>
<input name="button" type="button" οnclick="result.value=''" value="清空结果" /></td>
<td height="30"><input name="button" type="button" value="预览转换代码" /></td>
</tr>
</table>
</body>
</html>
转载于:https://blog.51cto.com/332374363/1081206