You learn science and technology with soft front-end: JavaScript output

JavaScript does not provide any built-in print or display function.

JavaScript display program

JavaScript can "display" data in different ways:

  • Use  window.alert () written warning box
  • Use  document.write () writes the HTML output
  • Use  innerHTML write HTML elements
  • Use  console.log () is written to the browser console

Using innerHTML

To access the HTML elements, JavaScript can use  document.getElementById (id) method.

id attribute defines HTML elements. innerHTML attribute defines HTML content:

Examples

<! DOCTYPE HTML> 
<HTML> 
<body> 

<h1> My first website </ h1> 

<the p-> My first paragraph </ the p-> 

<the p-the above mentioned id = "Demo"> </ the p-> 

< Script> 
 document.getElementById ( "Demo") the innerHTML + =. 5. 6. ;
 </ Script> 

</ body> 
</ HTML>

Using document.write ()

For testing purposes, using  document.write () is more convenient:

<! DOCTYPE HTML> 
<HTML> 
<body> 

<h1 of> My first page </ h1 of> 

<P> My first paragraph </ P> 

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

</ body> 
</ HTML>

Use window.alert ()

You can use the alert box to display the data:

Examples

<! DOCTYPE HTML> 
<HTML> 
<body> 

<h1 of> My first page </ h1 of> 

<P> My first paragraph </ P> 

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

</ body> 
</ HTML>

Use console.log ()

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

Please activate the browser console through F12, and select the menu "Console"

<! DOCTYPE HTML> 
<HTML> 
<body> 

<h1 of> My first page </ h1 of> 

<P> My first paragraph </ P> 

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

</ body> 
</ HTML>

Source: soft Technology (www.sysoft.net.cn)

Guess you like

Origin www.cnblogs.com/sysoft/p/11610903.html