Visualizzazione dei risultati da 1 a 2 su 2

Discussione: Problema con key enter

  1. #1

    Problema con key enter

    Ciao a tutti o questo tag html:

    codice HTML:
    <input type="text" name="msgChat" placeholder="Scrivi qui..." onkeyup="sendMsg();">
    e questo js:
    codice:
    function sendMsg() {
        const sendKey = document.querySelector("input[name=msgChat]");
        sendKey.addEventListener("keyup", (event) => {
            if (event.key === "Enter") alert(sendKey.value);
        });
    }
    
    Ma quando lo eseguo mi compare tante alert quanti caratteri digito nel campo input invece mi dovrebbe dare solo 1 alert

  2. #2
    ok risolto con stopImmediatePropagation()

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.