想实现个功能,表格按住shift实现多选,我的思路是这样,监听键盘事件,keydown时变量onshift=true,keyup时变量onshift=false,在点击行时判断此变量是否为true。keydown能监听到,但是多选后keyup就失效,不清楚为啥,难道是因为键盘和鼠标一起就不好用?代码如下:mounted(){ document.onkeydown = (e) => {
let key = window.event.keyCode;
alert(key) if (key == 17) { this.onctrl = true;
} if (key == 16) { this.onshift = true;
}
alert(this.onshift)
}; document.onkeyup = (e) => { this.onctrl = false; this.onshift = false;
};
},
添加回答
举报
0/150
提交
取消