简体   繁体   English

这个提交按钮是用javascript创建的,不起作用,有人可以帮我吗?

[英]this submit button is created with javascript and doesn't work, can anyone help me?

This submit button is created with JavaScript and doesn't work.这个提交按钮是用 JavaScript 创建的,不起作用。 Can anyone help me?谁能帮我?

<html>
<body>

<p>Click the button to create a Submit Button.</p>

<button onclick="myFunction()">Try it</button>
<form name="coba" method="POST" action="Menu.php">
<script>
//create submit button
function myFunction() {
    var x = document.createElement("INPUT");
    x.setAttribute("type", "submit");
    document.body.appendChild(x);
}
</script>

</body>
</html>

As suggested in the comments above, the new button needs to be appended to the form and not directly to the body .正如上面评论中所建议的,新按钮需要附加到form而不是直接附加到body So, to identify the form, the relevant code should be added too:因此,为了识别表单,还应添加相关代码:

 <html> <body> <p>Click the button to create a Submit Button.</p> <button onclick="myFunction()">Try it</button> <form name="coba" id="coba" method="POST" action="Menu.php"> </form> <script> //create submit button function myFunction() { var x = document.createElement("INPUT"); x.setAttribute("type", "submit"); document.getElementById("coba").appendChild(x); } </script> </body> </html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM