【发布时间】:2012-03-11 14:34:34
【问题描述】:
我在这里看到了一些类似的问题(例如JavaScript: Check if CTRL button was pressed),但我的问题实际上是事件触发。我的js代码:
// Listen to keyboard.
window.onkeypress = listenToTheKey;
window.onkeyup = listenToKeyUp;
/*
Gets the key pressed and send a request to the associated function
@input key
*/
function listenToTheKey(e)
{
if (editFlag == 0)
{
// If delete key is pressed calls delete
if (e.keyCode == 46)
deleteNode();
// If insert key is pressed calls add blank
if (e.keyCode == 45)
createBlank();
if (e.keyCode == 17)
ctrlFlag = 1;
}
}
事件触发除 ctrl 之外的任何其他键。
我还需要为 ctrl 触发它。
我不能使用 jQuery/prototype/whatever,所以这些解决方案是不可接受的。
那么...我怎样才能检测到 ctrl?
【问题讨论】:
-
这不是:if (e.ctrlKey) { .... } work..?
标签: javascript ctrl