如何更改HTML DOM元素的生成位置?

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

我正在制作一个网页,允许用户添加他们的兴趣。我打算稍后将输入数据发送到WebAPI。我使用Javascript DOM为每个文本输入生成新的Button。然后我以表格形式添加了它。该功能运行正常,但问题是新生成的Button在我希望它们生成的Div之外生成。

这里是它的屏幕截图。Screenshot of the Webpage

<!doctype html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>IPT - Student Register</title>
<meta name="description" content="IPT - NSBM">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="apple-touch-icon" href="apple-icon.png">
<link rel="shortcut icon" href="favicon.ico">


<link rel="stylesheet" href="vendors/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="vendors/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="vendors/themify-icons/css/themify-icons.css">
<link rel="stylesheet" href="vendors/flag-icon-css/css/flag-icon.min.css">
<link rel="stylesheet" href="vendors/selectFX/css/cs-skin-elastic.css">

<link rel="stylesheet" href="assets/css/style.css">

<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800' rel='stylesheet' type='text/css'>
</head>
<body class="bg-dark">
<div class="sufee-login d-flex align-content-center flex-wrap">
    <div class="container">
        <div class="login-content">
            <div class="login-logo">
                <p>IPT Programme NSBM - NSBM - Student Registration</p>
            </div>
            <div class="login-form">
                    <div class="form-group">
                        <label>Enter your Qualifications</label>
                        <input type="text" class="form-control" id="myText" value=Qualification 1">
                            <br>
                            <button onclick="myFunction()">Add</button>
                            <br>   
                    </div>
            </div>
        </div>
    </div> 
</div>
<script>
    function myFunction() {
      var y = document.getElementById("myText").value;
      var x = document.createElement("INPUT");
      x.setAttribute("type", "button");
      x.setAttribute("value", y);
      document.body.appendChild(x);  
    }
    </script>
</body>
</html>

有没有一种方法可以用白色本身生成这些按钮?谢谢你们!

javascript html css forms dom
1个回答
0
投票

问题可能是您将按钮附加到了JavaScript中的网站正文上,而不是弹性容器div类上吗?也许您应该尝试严格在flex div中创建按钮,然后在JavaScript中添加其功能。希望这会有所帮助,并祝您好运:)

© www.soinside.com 2019 - 2024. All rights reserved.