JavaScript:检查CTRLbutton是否被按下

我需要检查CTRLbutton是否被按下,而我点击我的HTML页面上的控件使用JavaScript。

我怎样才能做到这一点?

尝试查看事件对象。

例如

document.body.onclick = function (e) { if (e.ctrlKey) { alert("ctr key was pressed during the click"); } } 

我用这个,工作正常

 <a href="" onclick="return Details(event)" ></a> function Details(event) { if (event.ctrlKey) { alert('Ctrl down'); } } 

检出事件的ctrlKey属性

我用cntrlIsPressed全局标志做了它; 还要照顾使用Control + Aselect所有选项

 // Check whether control button is pressed $(document).keydown(function(event) { if (event.which == "17") cntrlIsPressed = true; else if (event.which == 65 && cntrlIsPressed) { // Cntrl+ A selectAllRows(); } }); $(document).keyup(function() { cntrlIsPressed = false; }); var cntrlIsPressed = false;