有人能告诉我发生了什么事吗?我的控制台没有抛出任何异常。
function onKeyDown(){
var e = event.keyCode;
//if (e==87 /*w*/){
up = true;
throw('up');
//}
if (e==65 /*a*/){
left = true;
}
if (e==83 /*s*/){
down = true;
}
if (e==68 /*d*/){
right = true;
}
}
function onKeyUp(){
var e = event.keyCode;
//if (e==87 /*w*/){
up = false;
throw('up');
//}
if (e==65 /*a*/){
left = false;
}
if (e==83 /*s*/){
down = false;
}
if (e==68 /*d*/){
right = false;
}
}
Okay, so that was the javascript, and this is the html:
<body>
<input id="ss" type="button" value="start/stop" />
<div id="container" style="border:1px solid; cursor:none; width:480px; height:320px;">
<canvas id="canvas" width="480" height="320" onkeyup="onKeyUp();" onkeydown="onKeydown();">
Canvas not displaying.
</canvas>
</div>
</body>
Edit: current code:
窗口加载完成后执行以下函数:
function init(){
//这里是需要执行的代码
}
function init(){
initSettings();
initImages();
document.getElementById('canvas').onkeydown = function(event) {
var e = event.keyCode;
//if (e==87 /*w*/){
up = true;
throw('up');
//}
if (e==65 /*a*/){
left = true;
}
if (e==83 /*s*/){
down = true;
}
if (e==68 /*d*/){
right = true;
}
}