[英]Using arrow keys to navigate in a table
UPDATE UPDATE
I see that the code works in FF but not chrome, so the code itself works. 我看到代码可以在FF中运行,但不能在chrome中运行,因此代码本身可以运行。 Could it be to this part in the body?:
可能是身体的这一部分?
<body onkeypress="return onKeyPress(event)" onload="javascript:initBoard('Container'); makeBoard()">
What should I change to let Chrome pick up the key events too? 我应该怎么做才能让Chrome也接管关键事件?
END UPDATE 结束更新
I have a table I want to navigate in it using the arrow keys. 我有一个要使用箭头键浏览的表。 Problem is, it aint working.
问题是,它不能正常工作。 My javascript code:
我的JavaScript代码:
function setSel(x, y) {
// Wrap around off the edges of the board
if (x > 8) x = 0;
if (x < 0) x = 8;
if (y > 8) y = 0;
if (y < 0) y = 8;
var e = document.getElementById("Cell" + x + y);
if (!e)
return;
if (sel)
delClass(sel, "Selected");
sel = e;
addClass(sel, "Selected");
}
function onKeyPress(e) {
if (sel == null)
return;
var keynum;
var keychar;
var numcheck;
var e = window.event || e
keynum = e.keyCode == 0 ? e.which : e.keyCode;
switch(keynum) {
case 37: // left arrow
setSel(sel.x - 1, sel.y);
return false;
case 38: // up arrow
setSel(sel.x, sel.y - 1);
return false;
case 39: // right arrow
setSel(sel.x + 1, sel.y);
return false;
case 40: // down arrow
setSel(sel.x, sel.y + 1);
return false;
case 46: // backspace/delete/space
case 32:
case 8:
board.setValue(sel.x, sel.y, 0);
board.render();
return false;
default:
keychar = String.fromCharCode(keynum);
if ((/\d/).test(keychar)) {
var i = parseInt(keychar);
if (i >= 0 && i <= 9) {
board.setValue(sel.x, sel.y, parseInt(keychar));
board.render();
return false;
}
}
}
board.render();
return true;
}
I've found this fiddle: http://jsfiddle.net/BdVB9/ which does exactly what I need, but I am unsuccessful replicating it with my own code. 我发现了这个小提琴: http : //jsfiddle.net/BdVB9/确实可以满足我的需要,但是我用自己的代码将其复制失败。 So what am I missing?
那我想念什么呢?
经过更多研究后,Chromium似乎不支持箭头键: https : //code.google.com/p/chromium/issues/detail? id = 2606和http://help.dottoro.com/ljlwfxum。 PHP
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.