How does javascript output data?
There are four ways.
Method 1: Use window.alert() to pop up an alert box (emphasis).
Method 2: Use innerHTML to write to HTML elements (emphasis).
Method 3: Use the document.write() method to write the content into the HTML document.
Method 4: Use console.log() to write to the console of the browser.
window.alert() demo (emphasis)
index.htmlcode
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p>window.alert()</p>
<script>
window.alert(122);
</script>
</body>
</html>
plan:
innerHTML demo
First access the HTML element using the document.getElementById( id ) method.
Use the "id" attribute to identify HTML elements and innerHTML to insert element content.
This command can also be entered on the command line.
index.htmlcode
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p>innerHTML</p>
<p id="demo">Modified content</p>
<script>
document.getElementById("demo").innerHTML = "Modify content";
</script>
</body>
</html>
plan
document.write() Demo
If you do a document.write after the document has finished loading, the entire HTML page will be overwritten.
index.html
<!DOCTYPE html>
<html>
<body>
<p>document.write()</p>
<script>
document.write(122);
</script>
</body>
</html>
console.log() demo
index.html
<!DOCTYPE html>
<html>
<body>
<h1> console.log() </h1>
<script>
console.log(122);
</script>
</body>
</html>
Demo
The above are the four ways of javascript output data.
If you like it, you can like it or bookmark it, thank you!