创建动态文本框,但代码不起作用(Creating Dynamic Textbox , but code not working)

编程入门 行业动态 更新时间:2024-10-27 00:24:27
创建动态文本框,但代码不起作用(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();"/>

更多推荐

本文发布于:2023-07-23 00:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1225242.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   不起作用   代码   动态   Creating

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!