汉字与Unicode编码相互转换(Js版)
2012-12-07 09:50
543 查看
<!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" onclick="result.value=''" value="清空结果" /></td>
<td height="30"><input name="button" type="button" value="预览转换代码" /></td>
</tr>
</table>
</body>
</html>
参考:http://tool.chinaz.com/Tools/Unicode.aspx
红色:http://zhidao.baidu.com/question/289602652.html
<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" onclick="result.value=''" value="清空结果" /></td>
<td height="30"><input name="button" type="button" value="预览转换代码" /></td>
</tr>
</table>
</body>
</html>
参考:http://tool.chinaz.com/Tools/Unicode.aspx
红色:http://zhidao.baidu.com/question/289602652.html
相关文章推荐
- JavaScript汉字Unicode编码相互转换
- &#x(unicode编码后的汉字)JS转换方法
- &#x(unicode编码后的汉字)JS转换方法
- C#汉字Unicode编码相互转换
- 从SIM卡读出的unicode编码 通过js转换成汉字
- JavaScript汉字Unicode编码相互转换
- C#汉字Unicode编码相互转换
- js Unicode编码相互转换
- js Unicode编码相互转换
- C#汉字Unicode编码相互转换
- 汉字与Unicode编码相互转换(asp版)
- PHP实现Unicode编码相互转换的方法示例
- PHP实现Unicode和Utf-8编码相互转换
- \u格式 &# unicode与汉字的相互转换
- JAVA字符编码系列二:Unicode,ISO-8859,GBK,UTF-8编码及相互转换[引]
- PHP将汉字转换成Unicode编码的函数
- 数据库乱码问题 & Python 编码问题(Unicode 的 encode、decode 相互转换 )
- 关于JAVA字符编码:Unicode,ISO-8859-1,GBK,UTF-8编码及相互转换
- GB2312 编码和汉字相互转换
- java之配置文件中的汉字和unicode相互转换