“Input AddEventListener” Kode Jawaban

Input AddEventListener

// to get value from text input (or textarea):
// in html:
<input class="my-class">type something here with console opened</input>
// in js:
const myInputArea = document.querySelector(".my-class")
myInputArea.addEventListener("input", (e)=>{
  const myInputText = e.target.value
  console.log(myInputText)
})
                                                 
Disgusted Dunlin

On Change Event html tidak berfungsi

onchange is only triggered when the control is blurred. Try onkeypress instead.
Blue-eyed Bat

SetEventListeners membentuk input

const setEventListeners = (formElement) => {
  // Find all fields inside the form, and
  // make an array from them using the Array.from() method
  const inputList = Array.from(formElement.querySelectorAll(".form__input"));

  // Iterate over the resulting array
  inputList.forEach((inputElement) => {
    // add the input event handler to each field
    inputElement.addEventListener("input", () => {
      // Call the isValid() function inside the callback,
      // and pass the form and the element to be checked to it
      isValid(formElement, inputElement)
    });
  });
};
Cruel Cormorant

MDN Select Event

<input value="Try selecting some text in this element.">
<p id="log"></p>
Strange Shark

Jawaban yang mirip dengan “Input AddEventListener”

Pertanyaan yang mirip dengan “Input AddEventListener”

Lebih banyak jawaban terkait untuk “Input AddEventListener” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya