检查密钥代码时出错
问题描述:
我正在制作一个tic tac toe的小游戏。我正在使用JavaScript代码。我现在面临的问题是,我得到的JS控制台检查密钥代码时出错
'KeyboardEvent.keyLocation' is deprecated. Please use 'KeyboardEvent.location' instead.
并获得在console.I这个警告后,警告我不能够使用further.I有一个功能键,将检查按下的键。代码是
window.onkeyup=function()
{
var current_key = event.keyCode;
console.log(current_key);
if(current_key == 37) goleft();
if(current_key == 38) goup();
if(current_key == 39) goright();
if(current_key == 40) godown();
}
我该如何摆脱这个问题。
答
通行证event
给你的函数是这样的:
window.onkeyup = function(event) {
var current_key = event.keyCode;
console.log(current_key);
if(current_key == 37) goleft();
if(current_key == 38) goup();
if(current_key == 39) goright();
if(current_key == 40) godown();
};
答
做你做类似的事:
在keyPress
事件的对象使用类似
:keyPress="doSomething(event)"
那么JS :
function doSomething(e){
if (e.keyCode == "13") {
//do Somehing
}
}
尝试通过'功能N(**事件**)” – Jackson 2015-04-06 05:54:44