テキストボックス

出力欄:

解説

名前を入力すると出力欄にあいさつが出力されます。この部分は次のようになっています。

<p><label>お名前:<input id="input" onchange="foo()"></label></p>

<p id="output">出力欄:</p>

ここで呼び出している関数 foo() は次のように定義しています:

function foo() {
  const x = document.getElementById("input").value;
  document.getElementById("output").textContent = "こんにちは," + x + "さん!";
}