最近踩的字符坑有点多,自己写了个ASCII查询,不用求人了。
<html>
<head>
<title>ASCII码查询</title>
<style>
table { border-collapse:collapse; }
th, td { border:1px solid black; padding:10px; text-align:center; }
a { text-decoration:none; }
</style>
</head>
<body>
<center>
<h1>ASCII码查询</h1>
<input type="text" id="text" value=" "> <button id="button">查询</button>
<p id="p"></p>
<table id="table"></table>
<a href="http://www.jb51.net/tools/ASCII.htm" target="_blank">脚本之家</a>
</center>
<script>
function genTable() {
var d = 10;
var tr = document.createElement('tr');
for (i=0; i<d; i++) {
var th = document.createElement('th');
th.textContent = '代码';
tr.appendChild(th);
th = document.createElement('th');
th.textContent = '字符';
tr.appendChild(th);
}
table.appendChild(tr);
for (i=0; i<256; i++) {
var s = String.fromCharCode(i);
if (i % d == 0)
tr = document.createElement('tr');
var td = document.createElement('td');
td.textContent = i;
tr.appendChild(td);
td = document.createElement('td');
td.textContent = s;
tr.appendChild(td);
if (i % d == 0)
table.appendChild(tr);
}
}
genTable();
button.onclick = function(){
var c = text.value;
var ascii = '';
for (i=0; i<c.length; i++) {
if (i == 0)
ascii = c.charCodeAt(i);
else
ascii = ascii + ' + ' + c.charCodeAt(i);
}
p.textContent = c + ' = ' + ascii;
}
</script>
</body>
</html>