# 按键虚拟键盘
~~~
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
span{
border: 1px solid #cc00aa;
background: #99aaff;
display: inline-block;
width: 30px;
text-align: center;
}
</style>
</head>
<body>
<span id="s0">0</span>
<span id="s1">1</span>
</body>
<script type="text/javascript">
document.onkeydown=key_down;
function key_down(event)
{
var codeValue=event.keyCode;
switch(codeValue)
{
case 48:
// var sp0=document.getElementById("s0");
// sp0.style.backgroundColor="red";
showStyle("s0");
break;
case 49:
showStyle("s1");
break;
}
}
function showStyle(id)
{
var sp0=document.getElementById(id);
sp0.style.backgroundColor="red";
sp0.style.borderColor="blue";
}
</script>
</html>
~~~