日期:2014-05-16  浏览次数:20387 次

16进制形式的字符串,如\u0063\u0073\u0064\u006E,从文本框输入,怎样转为普通字符串,如csdn?
<!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>






------解决方案--------------------
alert(String.fromCharCode(67));
那将十六进制转成10进制,你懂的
------解决方案--------------------
    function fToString()
    {
            var str=document.getElementById("txtOldText").value;
    eval("s = '" + str + "'");
            document.getElementById("txtNewTxt").value=s;
 &