用鼠标按有反应,但是用键盘按没有反应,谢谢高手指点!键盘为DFBJK
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<link href="all.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
function $(id){
if(document.all)
return document.all[id];
else if(document.getElementById)
return document.getElementById(id);
else
return null;
}
function play(id){
$(id).style.backgroundColor = "#00CCFF"; switch(id){
case 'keyDo': $("pianoMusic").innerText += "Do "; break;
case 'keyRe': $("pianoMusic").innerText += "Re "; break;
case 'keyMi': $("pianoMusic").innerText += "Mi "; break;
case 'keySol': $("pianoMusic").innerText += "Sol ";break;
case 'keyLa': $("pianoMusic").innerText += "La "; break;
default:
break;
}}
function endPlay(id){
$(id).style.backgroundColor = "#FFFFFF";
}
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ns = ns || ns6;
var ie = document.all;var keysetId = null;
function setKeyFocus(newKeysetId){
keysetId = newKeysetId;
switch(keysetId){
case "myWidget":
document.onkeydown = handleKeyDownForX;
document.onKeypress = handleKeyDownForX;
document.onkeyup = handleKeyUpForX;
break;
default:
document.onkeydown = null;
document.onkeypress = null;
document.onkeyup = null;
break;
}
return;
}
function keyCode(e){
if(!e) e = window.event; //IE Event Model
if(ie) //IE & Opera Browser
return e.keyCode;
else if(ns) //Mozilla Serial Browser
return e.which;
else
return null;
}function autoplay(){
play('keyDo');
timerHandler = setTimeout("play();",500);
play('keyRe');
play('keyMi');
function handleKeyDownForX(e){
if(!e) e = window.event; // fix for IE
var code;
if(ie)
code = e.keyCode;
else if(ns)
code = e.which;
else { alert("Unknown Browser."); return; }
switch(code){
case 37: play('keyDo'); break; // Up Arrow
case 38: play('keyRe'); break; // Down Arrow
case 39: play('keyMi'); break; // Left Arrow
case 40: play('keySol'); break; // Right Arrow
case 107: play('keyLa'); break; // Right Arrow
default: window.status = "Please Press Right Keys"; break;
}
}
function handleKeyUpForX(e){
if(!e) e = window.event; // fix for IE
var code;
if(ie)
code = e.keyCode;
else if(ns)
code = e.which;
else { alert("Unknown Browser."); return; }
switch(code){
case 37: endPlay('keyDo'); break; // Up Arrow
case 38: endPlay('keyRe'); break; // Down Arrow
case 39: endPlay('keyMi'); break; // Left Arrow
case 40: endPlay('keySol'); break; // Right Arrow
case 107: endPlay('keyLa'); break; // Right Arrow
default: window.status = "Please Press Right Keys"; break;
}
}
function fangqiKeyFocus(newKeysetId){
keysetId = newKeysetId;
block.active = false;
}
}
</script>
</head>
<body>
<div class="miniframecontent" id="monipiano">
<div class="pianoBox">
<Div class="pianokey" id="keyDo" onmousedown="play('keyDo');" onmouseout="endPlay('keyDo');" >宮</Div>
<Div id="keyRe" class="pianokey"onmousedown="play('keyRe'); " onmouseout="endPlay('keyRe');">商</Div>
<Div id="keyMi" class="pianokey"onmousedown="play('keyMi'); " onmouseout="endPlay('keyMi');">角</Div>
<Div id="keySol" class="pianokey"onmousedown="play('keySol');" onmouseout="endPlay('keySol');">徵</Div>
<Div id="keyLa" class="pianokey"onmousedown="play('keyLa'); " onmouseout="endPlay('keyLa');">羽</Div>
<br />
</div>
<Br /><Br />
<a id="autoplayBtn" href="#" onclick="autoplay();return false;">開啓自動彈奏</a>
<a href="#" id="setKeyFocus"onClick="setKeyFocus();return false;">獲取鍵盤焦點</a>
<a href="#" id="fangqiKeyFocus" onClick="fangqiKeyFocus();return false;">放棄鍵盤焦點</a>
<Br /><Br />
<div id="pianoMusic"></div>
</div>
</bod
></html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<link href="all.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
function $(id){
if(document.all)
return document.all[id];
else if(document.getElementById)
return document.getElementById(id);
else
return null;
}
function play(id){
$(id).style.backgroundColor = "#00CCFF"; switch(id){
case 'keyDo': $("pianoMusic").innerText += "Do "; break;
case 'keyRe': $("pianoMusic").innerText += "Re "; break;
case 'keyMi': $("pianoMusic").innerText += "Mi "; break;
case 'keySol': $("pianoMusic").innerText += "Sol ";break;
case 'keyLa': $("pianoMusic").innerText += "La "; break;
default:
break;
}}
function endPlay(id){
$(id).style.backgroundColor = "#FFFFFF";
}
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ns = ns || ns6;
var ie = document.all;var keysetId = null;
function setKeyFocus(newKeysetId){
keysetId = newKeysetId;
switch(keysetId){
case "myWidget":
document.onkeydown = handleKeyDownForX;
document.onKeypress = handleKeyDownForX;
document.onkeyup = handleKeyUpForX;
break;
default:
document.onkeydown = null;
document.onkeypress = null;
document.onkeyup = null;
break;
}
return;
}
function keyCode(e){
if(!e) e = window.event; //IE Event Model
if(ie) //IE & Opera Browser
return e.keyCode;
else if(ns) //Mozilla Serial Browser
return e.which;
else
return null;
}function autoplay(){
play('keyDo');
timerHandler = setTimeout("play();",500);
play('keyRe');
play('keyMi');
function handleKeyDownForX(e){
if(!e) e = window.event; // fix for IE
var code;
if(ie)
code = e.keyCode;
else if(ns)
code = e.which;
else { alert("Unknown Browser."); return; }
switch(code){
case 37: play('keyDo'); break; // Up Arrow
case 38: play('keyRe'); break; // Down Arrow
case 39: play('keyMi'); break; // Left Arrow
case 40: play('keySol'); break; // Right Arrow
case 107: play('keyLa'); break; // Right Arrow
default: window.status = "Please Press Right Keys"; break;
}
}
function handleKeyUpForX(e){
if(!e) e = window.event; // fix for IE
var code;
if(ie)
code = e.keyCode;
else if(ns)
code = e.which;
else { alert("Unknown Browser."); return; }
switch(code){
case 37: endPlay('keyDo'); break; // Up Arrow
case 38: endPlay('keyRe'); break; // Down Arrow
case 39: endPlay('keyMi'); break; // Left Arrow
case 40: endPlay('keySol'); break; // Right Arrow
case 107: endPlay('keyLa'); break; // Right Arrow
default: window.status = "Please Press Right Keys"; break;
}
}
function fangqiKeyFocus(newKeysetId){
keysetId = newKeysetId;
block.active = false;
}
}
</script>
</head>
<body>
<div class="miniframecontent" id="monipiano">
<div class="pianoBox">
<Div class="pianokey" id="keyDo" onmousedown="play('keyDo');" onmouseout="endPlay('keyDo');" >宮</Div>
<Div id="keyRe" class="pianokey"onmousedown="play('keyRe'); " onmouseout="endPlay('keyRe');">商</Div>
<Div id="keyMi" class="pianokey"onmousedown="play('keyMi'); " onmouseout="endPlay('keyMi');">角</Div>
<Div id="keySol" class="pianokey"onmousedown="play('keySol');" onmouseout="endPlay('keySol');">徵</Div>
<Div id="keyLa" class="pianokey"onmousedown="play('keyLa'); " onmouseout="endPlay('keyLa');">羽</Div>
<br />
</div>
<Br /><Br />
<a id="autoplayBtn" href="#" onclick="autoplay();return false;">開啓自動彈奏</a>
<a href="#" id="setKeyFocus"onClick="setKeyFocus();return false;">獲取鍵盤焦點</a>
<a href="#" id="fangqiKeyFocus" onClick="fangqiKeyFocus();return false;">放棄鍵盤焦點</a>
<Br /><Br />
<div id="pianoMusic"></div>
</div>
</bod
></html>
解决方案 »
- 关于extend的问题
- 怎么用js获取指定表单的内容?
- 怎样把一大段汉字按字数分隔成数组
- 知道年,月,和第几个星期。如何得出这个星期是几月几日到几月几日?
- web窗口关闭时,要求 输入密码, 密码正 确则关闭 否则不关闭,怎么实现
- 如何设置弹出窗口上下左右居中?
- 在panel中 用ADD添加的组件怎么动态的删除呢?
- 怎么让一个按钮点一下让网页“返回”再点一下就关闭当前页,我觉着方法好想可是我不会写啊
- window.open()打开一个网页,怎样能自动为其填写好表单并提交呢?
- 如何用程序设置IE的安全级别!
- 在TD中动态添加INPUT后无法获得该INPUT的值??
- JS弹出窗口问题,来就有分,!!!!!!!!!!
.pianoBox{
height: 102px;
}.pianokey{
width: 35px;
height: 100px;
float: left;
border: solid 1px;
text-align: center;
margin: 0px 2px;
}