Soft technology leads you to learn the front end: Javascript output


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

JavaScript display scheme

JavaScript can “display” data in different ways:

  • UseWindow. Alert(), write warning box
  • UseDocument. Write(), write HTML output
  • UseInnerHTML writes HTML elements
  • UseConsole. Log(), write to browser console

Using innerHTML

To access HTML elements, JavaScript uses theDocument.getelementbyid (ID) method.

The ID attribute defines the HTML element. The innerHTML property defines HTML content:


My first web page

My first paragraph

 document.getElementById("demo").innerHTML = 5 + 6;

Use document. Write()

For testing purposes, use theDocument. Write(), which is convenient:

My first web page

My first paragraph

document.write(5 + 6);

Use window. Alert()

You can use the warning box to display data:


My first web page

My first paragraph

window.alert(5 + 6);

Use console. Log ()

In the browser, you can use theConsole. Log () method to display the data.

Use F12 to activate the browser console and select console from the menu

My first web page

My first paragraph

console.log(5 + 6);

Source: Soft Technology (www.sysoft. Net. CN)

Recommended Today

Single and multiple buttons are styled with pictures

I’ve always seen people asking how to style and enlarge the buttons of radio buttons and multi buttons? Let’s share an example I did. 1. First make the button into a picture  2.html page Copy code The code is as follows: <!DOCTYPE HTML> <html> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ /> <script type=”text/javascript” src=”jquery-1.10.2.min.js”></script> <script type=”text/javascript”> […]