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")
}
}