Home  >  Article  >  Web Front-end  >  JavaScript listens to key events in textarea_javascript skills

JavaScript listens to key events in textarea_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:45:021493browse

There is a textarea,
Java code

Copy code The code is as follows:



often defines onKeyPress="keypress();" and defines the following method.
Copy code The code is as follows:

var keypress = function(e){
var e = e || window.event;
var k = e.keyCode;
}

The method I use here is JQuery.
Copy code The code is as follows:

$("#text").bind("keyPress ",function(event){
var k = event.which;
});

The which used here is whether it is a single key or a combination in IE or FF. The key is pressed, and its value is 107
Then use String.fromCharCode(k) to get the pressed value.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn