layui table 光标根据上下左右按键在table中移动并选中单元格内容

$(document).on('keydown', '.layui-input',
        function (event) {
            var td = $(this).parent('td');
            var index = td.index();
            var tr = td.parent('tr');
            switch (event.key) {
                case "ArrowUp"://上键
                    tr['prev']().children('td').eq(index).click();
                    setTimeout(function(){
                        $('.layui-table-edit').select(),0
                    });
                    break;
                case "ArrowDown"://下键
                    tr['next']().children('td').eq(index).click();
                    setTimeout(function(){
                        $('.layui-table-edit').select(),0
                    });
                    break;
                case "ArrowLeft"://左键
                    td['prevAll']('[data-edit="text"]:first').click();
                    setTimeout(function(){
                        $('.layui-table-edit').select(),0
                    });
                    break;
                case "ArrowRight"://右键
                    td['nextAll']('[data-edit="text"]:first').click();
                    setTimeout(function(){
                        $('.layui-table-edit').select(),0
                    });
                    break;
            }
        });

你可能感兴趣的:(layui,javascript,html)