+ 1
How i recognize enter key is pressed using JavaScript
6 Réponses
+ 4
e.which is more reliable than e.keyCode when it comes to compatibility if you're using jQuery.
just my 2c
+ 4
Saurabh Kasaudhan Use" e.which" insteadof "e.keyCode" as Jonathan Pizarra said.
+ 3
<script>
<input id="area" type="text" onkeypress="return run(event)" />
</script>
function run(e) {
if (e.keyCode == 13) {
var test = document.getElementById("area").value;
alert (test)
}
}
may not work on some device's because of Placing "Enter" key in different places so you have to find the keycode of your keyboard
+ 1
<input onkeydown="console.log('key is pressed')"; />
0
ok