Home > Web Front-end > JS Tutorial > body text

There are several printing methods in javascript

王林
Release: 2023-01-07 11:42:55
Original
17460 people have browsed it

There are three printing methods in JavaScript, namely window.alert(), document.write() and console.log().

There are several printing methods in javascript

#The operating environment of this article: windows10 system, javascript 1.8.5, thinkpad t480 computer.

In JavaScript, we usually use the following three ways to print data:

  • Use window.alert() to write the warning box

  • Use document.write() to write HTML output

  • Use console.log() to write to browser console

Let’s take a look at how they are used.

Using window.alert()

You can use an alert box to display data:

Example

<!DOCTYPE html>
<html>
<body>

<h1>我的第一张网页</h1>

<p>我的第一个段落</p>

<script>
window.alert(5 + 6);
</script>

</body>
</html>
Copy after login

Use document.write()

For testing purposes, it is more convenient to use document.write():

Example

<!DOCTYPE html>
<html>
<body>

<h1>我的第一张网页</h1>

<p>我的第一个段落</p>

<script>
document.write(5 + 6);
</script>

</body>
</html>
Copy after login

Use console.log()

In the browser, you can Use the console.log() method to display data.

Please activate the browser console via F12 and select "Console" in the menu.

Example

<!DOCTYPE html>
<html>
<body>

<h1>我的第一张网页</h1>

<p>我的第一个段落</p>

<script>
console.log(5 + 6);
</script>

</body>
</html>
Copy after login

Related video tutorial sharing: javascript video tutorial

The above is the detailed content of There are several printing methods in javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template