简体   繁体   English

动态创建HTML表单

[英]Create HTML forms dynamically

I'm creating a web page with a Google Maps window, it is in JavaScript and HTML. 我正在创建一个带有Google Maps窗口的网页,它使用JavaScript和HTML。 I'm wondering, can I create a new HTML form each time the user clicks on a new point in the map? 我想知道,每次用户单击地图中的新点时,我都可以创建一个新的HTML表单吗? I've been looking online and am having a hard time finding anything on this, if someone could point me in the right direction that would be awesome. 我一直在网上寻找,如果有人能指出正确的方向,那真是太难了。

Each time the user clicks on a point on the map it creates a way point, I want a couple new forms on the page to pop up so that the user can input information (things like name, descriptin, etc) to be associated with that waypoint they just created. 每次用户单击地图上的一个点都会创建一个航路点,我希望在页面上弹出几个新表单,以便用户可以输入要与之相关联的信息(例如名称,descriptin等)他们刚刚创建的航点。 I also want a button next to each form that will remove it when clicked in case the user enters a waypoint accident. 我还希望每个表单旁边都有一个按钮,当用户输入航路点事故时,单击该表单时将其删除。

Thanks so much! 非常感谢!

One way would be to have a div tag to contain the form in and then using JavaScript build the new form in a string and then update the contents of the div (using the .innerHTML property) with the new form. 一种方法是让div标签包含表单,然后使用JavaScript在字符串中构建新表单,然后使用新表单更新div的内容(使用.innerHTML属性)。

<div id="divForms"></div>

string newForm = "<input type='text' id='txtName1' />";

document.getElementById("divForms").innerHTML = newForm;

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

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