简体   繁体   中英

Create HTML forms dynamically

I'm creating a web page with a Google Maps window, it is in JavaScript and HTML. I'm wondering, can I create a new HTML form each time the user clicks on a new point in the map? 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. 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 id="divForms"></div>

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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