Introduction to commonly used input and output statements in JavaScript

In daily development, in order to facilitate data input and output, JavaScript provides some commonly used input and output statements, as shown in Table 1-3.

Table 1 Commonly used input and output statements

Insert image description here

Next, we will demonstrate the use of document.write0, console.log0 and promptO respectively.

1. document.write()

If the output content of document.write0 contains HTML tags, it will be parsed by the browser. The following uses documentL.write0 to output "I am the document.write0 statement!" on the page. The sample code is as follows.

document.write('I am a document.write() statement!');

2. console.log()

Use the console.log0 statement to output "I am the console.log0 statement!" on the console. The sample code is as follows.

console.log('I am a console.log() statement!');
The output of console:.log0 needs to be viewed in the browser's console. Press the "F12" key in the Chrome browser (or right-click on a blank area of ​​the web page and select "Inspect" in the pop-up menu) to start the developer tools, and then switch to the "Console" panel to see The output of console.log0.

3.prompt()

Use the prompt0 statement to pop up an input box with prompt information on the page. The sample code is as follows.

prompt(Please enter your name: ');
After the above sample code is run, an input box will pop up on the page and prompt the user "Please enter your name:" prompt box.

Guess you like

Origin blog.csdn.net/cz_00001/article/details/133034976