Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created November 10, 2021 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/6e88860485a6dfa04e88e121974231b0 to your computer and use it in GitHub Desktop.
Save parzibyte/6e88860485a6dfa04e88e121974231b0 to your computer and use it in GitHub Desktop.
document.addEventListener("DOMContentLoaded", () => {
const $codigo = document.querySelector("#codigo");
$codigo.addEventListener("keydown", evento => {
if (evento.keyCode === 13) {
// El lector ya terminó de leer
const codigoDeBarras = $codigo.value;
// Aquí ya podemos hacer algo con el código. Yo solo lo imprimiré
console.log("Tenemos un código de barras:");
console.log(codigoDeBarras);
// Limpiar el campo
$codigo.value = "";
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment