结合alt和按键事件的javascript. [英] javascript making combination of alt and a key press events.
问题描述
大家好,
我正在通过键盘按在网格视图中选择单选按钮.我正在选择''a''和''d''键选择时选择单选按钮.
但是现在我想将"alt"组合键与键"a"和"d"组合在一起.
所以给我任何想法我该怎么做.以下是我用来执行关键事件的代码.但是我不明白该如何结合使用alt键.
请帮我...
Hello Every One,
I am selecting radio button in grid view on key press from keyboard. I am selecting radio button on selection of ''a'' and ''d'' key press.
But now i want to make combination of ''alt'' key combination with keys ''a'' and ''d''.
So give me any idea how can i do this. following is code which i am using to perform key events. But i am not understanding that how can i make combination of alt key with this.
please help me...
<script type="text/javascript">
document.onkeypress = clickRadio;
function clickRadio(e) {
if (window.event)
var keyCode = window.event.keyCode; // IE
else
var keyCode = e.which;
if (keyCode == 65 || keyCode == 97 || keyCode == 68 || keyCode == 100) {
setRadioButton(keyCode);
}
}
function setRadioButton(whichKey) {}</script>
推荐答案
尝试以下操作:
把它放在体内:
Try This:
Put This In The Body:
<BODY onload="document.body.focus();" onkeydown="AltDown();">
这是检测ALT的功能:
This Is The Function To Detect The ALT:
function AltDown() {
if (window.event.altLeft) {
alert("altLeft Pressed");
}
else {
if (window.event.altKey) {
alert("altRight Pressed");
}
}
//To Cancel The Event
window.event.returnValue = false;
document.body.focus();
}
这是来自 http://www.w3schools的摘录.com/jsref/event_onkeypress.asp [ ^ ]
This is an extract from http://www.w3schools.com/jsref/event_onkeypress.asp[^]
在所有浏览器中,不会为所有键(例如ALT,CTRL,SHIFT,ESC)触发onkeypress事件.要仅检测用户是否已按下键,请使用 onkeydown [
The onkeypress event is not fired for all keys (e.g. ALT, CTRL, SHIFT, ESC) in all browsers. To detect only whether the user has pressed a key, use the onkeydown[^] event instead, because it works for all keys.
您可以使用event.altKey
,event.ctrlKey
,event.shiftKey
谓词检查是否按下了各个修饰符.
You can use event.altKey
, event.ctrlKey
, event.shiftKey
predecates to check if respective modifiers are pressed.
这篇关于结合alt和按键事件的javascript.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!