Cha*_* Ma 99
尝试查看事件对象.
例如
document.body.onclick = function (e) {
if (e.ctrlKey) {
alert("ctr key was pressed during the click");
}
}Run Code Online (Sandbox Code Playgroud)
<p>Click me, and sometimes hold CTRL down!</p>Run Code Online (Sandbox Code Playgroud)
检查是否按下了 CTRL 按钮。我用这个并且效果很好。
<a href="" onclick="return Details(event)" ></a>
function Details(event) {
if (event.ctrlKey) {
alert('Ctrl down');
}
}
Run Code Online (Sandbox Code Playgroud)
我使用 cntrlIsPressed 全局标志来做到这一点;还可以使用 Control + A 选择所有选项
// 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;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
38651 次 |
| 最近记录: |