html utilize JavaScript The typed data is displayed one after another



<html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body> <div id="div" class="c1"></div> <form action=""> <input type="text" id="a"> <button type="button" onclick="add()">dd</button> <p> </p> </form></body><script> function add(){ document.getElementById("a").innerHtml }</script></html>
The answer code of your question is as follows :( If help , Hope to adopt ! thank you ! Click on the... At the top right of my answer 【 Adopt 】 Button )
<!doctype html><html lang="en"><head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <title> Page name </title></head><body><input type="text" id="text" value="" /><input type="button" value="dd" onclick="fp();" /><div id="box"></div><script type="text/javascript">function fp() { var str = document.getElementById("text").value; var div = document.createElement("div"); div.innerHTML = str; var box = document.getElementById("box"); box.appendChild(div);}</script></body></html>
Simpler
<!doctype html><html lang="en"><head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <title> Page name </title></head><body><input type="text" id="text" value="" /><input type="button" value="dd" onclick="fp();" /><div id="box"></div><script type="text/javascript">function fp() { var str = document.getElementById("text").value; var box = document.getElementById("box"); box.innerHTML += str+"<br>";}</script></body></html>
use document.getElementById("a").innerHtml
Append after clicking the button or append during input