在通过键盘控制行 上下滑动的时候,遇到一个keydown无效的问题。
具体参考: https://www.cnblogs.com/goloving/p/13220359.html
$(document).on("keydown", "#uiLayoutCenter", function (event) {
let arrs = $("#bootstrap-table").bootstrapTable('getSelections');
if (arrs.length == 1) {
let data = $("#bootstrap-table").bootstrapTable('getData');
for (let j = 0; j < data.length; j++) {
if (data[j].stockId == arrs[0].stockId) {
if (event.keyCode === 38) { // up
if (j > 0) {
$("#bootstrap-table").bootstrapTable('uncheckBy', { field: 'stockId', values: [arrs[0].stockId] });
$("#bootstrap-table").bootstrapTable('checkBy', { field: 'stockId', values: [data[j - 1].stockId]});
} else {
break;
}
} else if (event.keyCode === 40) { // down
if (j < data.length - 1) {
$("#bootstrap-table").bootstrapTable('uncheckBy', {field: 'stockId', values: [arrs[0].stockId] });
$("#bootstrap-table").bootstrapTable('checkBy', {field: 'stockId', values: [data[j + 1].stockId]});
} else {
break;
}
}
}
}
}
event.preventDefault();
});```