jQuery set variable to -1 if up arrow key pressed or to increment variable
I have this code
I use jkey to simplify the usage on detecting which key is pressed.
Question
What i want is when any other except up arrow key开发者_JAVA技巧 is pressed set the value of count
to -1
and if up arrow key is pressed do it just like in the code.
Is there a way out by using the jKey plugin ? if not then how do i do it with normal jquery
This obviously doesn't get you exactly where you want to go but it should get you started.
HTML
<textarea id="myBigText"></textarea>
JS
$(document).ready(function() {
$("#myBigText").keydown(function(evt) {
evt = evt || window.event;
var charCode = evt.which || evt.keyCode;
if(charCode == 38) {
alert("This is the up arrow key");
} else {
alert("This is not the up arrow");
}
});
});
jKey doesn't work this way. You have to explicitly tell it what you want to look for. There's no "any key" option. You should fork it on github and add in this feature.
精彩评论