dom_dom0500_002

入力イベントを監視したい場合に使うイベントはどれですか?

[ html ]

<input type="text" id="nameInput">
  1. click
  2. keydown
  3. input
  4. submit
正解
  1. input
解説

inputイベントはユーザーが入力フィールドの値を変更するたびに発生します。リアルタイムの検出に有効です。

使用例(サンプルコード)

[ javascript ]

const input = document.getElementById("nameInput");
input.addEventListener("input", (e) => {
  console.log("入力値:", e.target.value);
});