html代码
封装的jq代码
/**
* 方向键移动
*/
$('#id').keyup(function (e) {
var $input,
idx = $(e.target).parent().index()
switch (e.keyCode) {
case 37:
$input = $(e.target).parent().prev().children()
$input.length > 0 && $input.focus()
break;
case 39:
$input = $(e.target).parent().next().children()
$input.length > 0 && $input.focus()
break;
case 38:
$input = $($(e.target).parents('tr').prev().children()[idx]).children()
$input.length > 0 && $input.focus()
break;
case 40:
$input = $($(e.target).parents('tr').next().children()[idx]).children()
$input.length > 0 && $input.focus()
break;
}
})
记录一下