JS键盘键捕捉 ctrlKey和shiftKey

JS键盘键捕捉

背景:在做项目的过程中,不仅会使用到单击和双击事件,经常也会用到Ctrl键,按住ctrl键选择多项。
一、Ctrl键 ctrlKey
 function doKeyDown()
    {
    
    
        if (event.ctrlKey)
        {
    
    
          alert("You pressed the Ctrl")
        }
    }
二、Ctrl键 + Enter键
 function doKeyDown()
    {
    
    
        if (event.ctrlKey && event.keyCode == 13)
        {
    
    
          alert("You pressed the Ctrl + Enter")
        }
    }
三、Shift键 shiftKey
 function doKeyDown()
    {
    
    
        if (event.shiftKey)
        {
    
    
          alert("You pressed the Shift")
        }
    }

猜你喜欢

转载自blog.csdn.net/sunshineTing2/article/details/129427320