I want the value to be inserted into the HTML page using jQuery by pressing Enter .
The code below is input
simple HTML:
<!doctype html>
<html>
<head>
<title>Somar Arrays</title>
</head>
<body>
<section class="vetores">
<p>Adicione números:</p>
<input type="text"><button>+</button>
</section>
<section class= "imprimir"></section>
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script><scriptsrc="funcao.js"></script>
</body>
</html>
The code below, in JavaScript, allows values to be entered with the mouse click, but how do I work when I press enter ?
var main = function() {
"use strict";
//Permite que os valores sejam inseridos a partir do click do mouse
$(".vetores button").on("click", function(event){
var $nro;
if ($(".vetores input").val() !== "") {
$nro = $("<p>").text($(".vetores input").val());
$(".imprimir").append($nro);
$(".vetores input").val("");
}
});
//Permite que os valores sejam inseridos a partir da tecla enter
$(".vetores button").on("keypress", function(event){
var $nro;
if(event.keyCode === 13){
if ($(".vetores input").val() !== "") {
$nro = $("<p>").text($(".vetores input").val());
$(".imprimir").append($nro);
$(".vetores input").val("");
}
}
});
};
$(document).ready(main);