<html>
<head>
<title>Unicode 编码转换器</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type=text/css>
body { background-color: white; margin-top: 24px; }
h1 { font: normal 20px '黑体'; text-align: center; color: black; }
td, textarea, input, select { font: normal 12px 'Courier New'; color: black; }
</style>
<script language="JavaScript">
function paste() { //粘帖
var clipboard = window.clipboardData.getData('text');
clipboard == null ? alert('您的剪切板中没有任何文本内容') : source.value = clipboard;
}
function A2U() { //ASCII -> Unicode转换
if (parseFloat(ScriptEngineMajorVersion() + '.' + ScriptEngineMinorVersion()) < 5.5) { alert('您的脚本引擎版本过低,请升级为5.5以上'); return; }
if (source.value == '') { alert('文本框中没有代码'); return; }
result.value = '';
for (var i=0; i<source.value.length; i++)
result.value += '&#' + source.value.charCodeAt(i) + ';';
}
function U2A() { //Unicode -> ASCII转换
var code = source.value.match(/&#(/d+);/g);
if (code == null) { alert('文本框中没有合法的Unicode代码'); return; }
result.value = '';
for (var i=0; i<code.length; i++)
result.value += String.fromCharCode(code[i].replace(/[&#;]/g, ''));
}
function preview() { //预览
var win = window.open();
win.document.open('text/html', 'replace');
win.document.writeln(result.value);
win.document.close();
}
function copy() { //复制
result.value == '' ? alert('没有需要复制的代码') : window.clipboardData.setData('text', result.value);
}
</script>
</head>
<body>
<table width="750" align="center"><tr><td>
<h1>Unicode 编码转换器 1.0</h1>
<hr>
<input type="button" value="1.粘帖" οnclick="paste();">(将需要进行转换的代码粘帖到下面的文本框中)
<textarea style="width:750px;height:180px;" id="source"></textarea><br><br>
<hr>
2.<input type="button" value="ASCII -> Unicode" οnclick="A2U();"> <input type="button" value="Unicode -> ASCII" οnclick="U2A();">(点击相应格式转换按钮将完成代码的转换)
<textarea style="width:750px;height:180px;" id="result"></textarea><br><br>
<hr>
<input type="button" value="3.预览" οnclick="preview()">(查看转换后的效果)
<img width="100" height="1">
<input type="button" value="4.复制" οnclick="copy();">(复制转换后的代码到剪贴板中)
<br>
<hr>
</td></tr></table>
</body>
</html>