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

JavaScript listens to key events in textarea_javascript skills

WBOY
Release: 2016-05-16 18:45:02
Original
1517 people have browsed it

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.
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template