日期:2014-05-16 浏览次数:20414 次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title></title>
<style type="text/css">
textarea
{
width:400px;
height:100px;
margin:0 10%;
}
</style>
<script type="text/javascript">
function fToUnicode()
{
var str=document.getElementById("txtOldText").value;
document.getElementById("txtNewTxt").value=toUnicode(str);
}
function fToString()
{
var str=document.getElementById("txtOldText").value;
document.getElementById("txtNewTxt").value=unescape(str);
}
function toUnicode(theString)
{
var unicodeString = '';
for (var i=0; i < theString.length; i++) {
//var theUnicode = theString.charCodeAt(i).toString(16).toUpperCase();
var theUnicode = theString.charCodeAt(i).toString(16).toLowerCase();
while (theUnicode.length < 4) {
theUnicode = '0' + theUnicode;
}
theUnicode = '\\u' + theUnicode;
unicodeString += theUnicode;
}
return unicodeString;
}
</script>
</head>
<body>
<textarea name="txtOldText" id="txtOldText" cols="30" rows="10" value="\\u1234"></textarea>
<input type="button" value="ToUnicode" onclick="fToUnicode()" />
<input type="button" value="ToString" onclick="fToString()" />
<hr />
<textarea name="txtNewTxt" id="txtNewTxt" cols="30" rows="10"></textarea>
</body>
</html>
function fToString()
{
var str=document.getElementById("txtOldText").value;
eval("s = '" + str + "'");
document.getElementById("txtNewTxt").value=s;
&