0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

JS 入力表示リスト

Posted at

JSでテキストボックスに入力してボタンを押すと下にリスト表示。

すぐに忘れるので覚書しています。
もっといい方法があればコメント頂けたらありがたいです。


<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="utf-8">
  <title>JS入力表示リスト</title>
</head>
<body>

<form name="form01">
<p>メッセージを入力してください</p>
<input type="text" id="message" name="message" size="40">
<input type="button" id="btn" value="OK" />
</form>
<ul>
</ul>

<script>
window.onload = function(){
    document.getElementById('btn').onclick = function(){
      var name = document.form01.message.value;
      console.log(name);
      const item2 = document.createElement('li');
      item2.textContent = name;
      const ul = document.querySelector('ul');
      ul.appendChild(item2);
    };
};
</script>

</body>
</html>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?