创建动态文本框,但代码不起作用(Creating Dynamic Textbox , but code not working)
我刚刚开始学习java脚本。我正在尝试制作动态文本框但我的代码不起作用。 有人可以帮我纠正我的错误吗?
<html> <head> </head> <body> <script language="javascript"> function add(){ var text=document.createElement('input'); var add=document.getElementById("Myform"); text.setAttribute("type","text"); text.setAttribute("name","BookName"); add.appendChild(text); } </script> <form action="new1.php" id="Myform"> <input type="submit" value="Submit" id="submit" onclick="javascript:add();"/> <br/> </form> </body> </html>在我可以使用它之前,文本框消失了。
I have just started learning java script.I am trying to make Dynamic text box but the my code is not working . Can someone help me in rectifying my mistake??
<html> <head> </head> <body> <script language="javascript"> function add(){ var text=document.createElement('input'); var add=document.getElementById("Myform"); text.setAttribute("type","text"); text.setAttribute("name","BookName"); add.appendChild(text); } </script> <form action="new1.php" id="Myform"> <input type="submit" value="Submit" id="submit" onclick="javascript:add();"/> <br/> </form> </body> </html>The text box disappears before I can do anything with it.
最满意答案
将输入类型更改为按钮或其他方式将提交表单。您想要提交按钮意味着您必须再添加一个按钮以进行动态操作。
<input type="button" value="Submit" id="submit" onclick="javascript:add();"/>Change the input type as button or other wise it will submit the form.You want the submit button means you have to add one more button for dynamic action.
<input type="button" value="Submit" id="submit" onclick="javascript:add();"/>更多推荐
发布评论