(JS DOM) 在 div 中创建新元素

问题描述 投票:0回答:0

所以,我试图制作一个网络应用程序,它的行为类似于使用文本区域元素作为输入的机器人。在参考 W3Schools 提供的JS DOM 文档时,我发现我的代码无法正常工作。我也是 JS DOM 的新手,所以如果我是你见过的最愚蠢的人,请原谅我。 (我可能是)

代码:

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>replit</title>
  <link href="https://bot.valueyu.repl.co/style.css" rel="stylesheet" type="text/css" />
  <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
  <script src="script.js"></script>
</head>

<script>
  function reply() {
    const rplyBox = document.getElementById('rplyBox')
    const input = document.getElementById('msgBox').value;
    if (input === "help") {
      const embed = document.createElement("div");
      embed.classList.add("w3-round-xxlarge", "w3-margin-top", "w3-margin-bottom", "w3-margin-right", "w3-margin-left")
      const title = document.createElement("h1")
      title.createTextNode("Help");
      const desc = document.createElement("h3")
      desc.createTextNode("All of my commands!");
      const field1 = document.createElement("h6")
      field1.createTextNode("e");
      embed.appendChild(title);
      embed.appendChild(desc);
      embed.appendChild(field1);
      rplyBox.appendChild(embed);
    }
  }
</script>

<body style="background-image: url('https://bot.valueyu.repl.co/bg.mp4'); background-repeat: no-repeat; background-size: cover;">
  <div class="main">
    <t>bot.valueyu</t>
    <p>bot.valueyu is a bot made by Aarav Saini/Valueyu. For commmands type "<span
        class="w3-text-white">help</span>".</p>
    <hr>
    <textarea class="w3-round-large w3-bar" id="msgBox"></textarea>
    <br>
    <br>
    <br>
    <button id="submit" onClick="reply()" class="w3-round-xxlarge w3-button">Send</button>
    <hr>
    <div class="w3-bar w3-white w3-round-large" id="rplyBox">

    </div>
  </div>
</body>

</html>
任何帮助将不胜感激。

javascript html input textarea jsdom
© www.soinside.com 2019 - 2024. All rights reserved.