HTML uses JavaScript to type data and display them one after another

CSDN Q & A 2022-02-13 07:19:54 阅读数:628

html uses javascript type data

html utilize JavaScript The typed data is displayed one after another

img

img

img

<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>



Take the answer :

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>


Other answers 2:

use document.getElementById("a").innerHtml


Other answers 3:

Append after clicking the button or append during input

copyright:author[CSDN Q & A],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130719526193.html