记下来 自己看

 

首先阻止浏览器的默认事件

//阻止浏览器默认事件

            document.addEventListener('keydown',this.handleEvent)

 

handleEvent(event){

                if (event.keyCode === 37) {

                console.log('拦截到37');

                this.switchBno(false);//自己的方法 37=←

                 event.preventDefault();

                 event.returnValue = false;

                 return false;

                }else if(event.keyCode === 39){

                    console.log('拦截到39');

                    this.switchBno(true);//39=→

                    event.preventDefault();

                     event.returnValue = false;

                     return false;

                }else if(event.keyCode === 83 && event.ctrlKey){

                    console.log('拦截到83+ctrl');//ctrl+s

                    this.saveData();

                    event.preventDefault();

                     event.returnValue = false;

                     return false;

                }else if(event.keyCode === 81 && event.ctrlKey){

                    console.log('拦截到Q+ctrl');

                    this.addWatermark();//ctrl+q

                    event.preventDefault();

                     event.returnValue = false;

                     return false;

                }

            },

 

 event.preventDefault();                  event.returnValue = false;   可能也不需要写

 

//需要销毁事件 防止全局生效

document.removeEventListener('keydown', this.handleEvent);

Logo

前往低代码交流专区

更多推荐