Get the App
SLTechnology News&Howtos  ›  Development  › 

How is JavaScript output

Shulou Source: shulou.com Published: 2022-06-03 09:40:54 10月10日 Update

Today, I will talk to you about how JavaScript is output. maybe many people don't know much about it. In order to make you understand better, the editor summed up the following content for you. I hope you can get something according to this article.

JavaScript is the most popular scripting language on the Internet, which can be used in HTML and web, and can be widely used in devices such as servers, PC, laptops, tablets and smartphones. JavaScript does not have any functions for printing or outputting.

JavaScript display data

JavaScript can export data in different ways:

Use window.alert () to pop up the alert box.

Use the [xss_clean] () method to write the content to the HTML document.

Use innerHTML to write to the HTML element.

Use console.log () to write to the browser's console.

Use window.alert ()

You can pop up a warning box to display the data:

Example

My first page

My first paragraph.

Window.alert (5 + 6)

Manipulate HTML elements

To access a HTML element from JavaScript, you can use the document.getElementById (id) method.

Use the "id" attribute to identify the HTML element, and innerHTML to get or insert the element content:

Example

My first Web page, my first paragraph.

Document.getElementById ("demo") [xss_clean] = "paragraph has been modified."

The above JavaScript statement (in the tag) can be executed in a web browser:

Document.getElementById ("demo") is the JavaScript code that uses the id attribute to find the HTML element.

InnerHTML = "paragraph has been modified." Is the JavaScript code used to modify the HTML content (innerHTML) of an element.

In this tutorial

In most cases, in this tutorial, we will use the methods described above to output:

The above example directly translates the id= "demo"

The element is written to the HTML document output:

Write to HTML document

For testing purposes, you can write the JavaScript directly in the HTML document:

Example

My first Web page

My first paragraph.

[xss_clean] (Date ())

Please use [xss_clean] () to output only what is written to the document.

If you execute [xss_clean] after the document has finished loading, the entire HTML page will be overwritten.

Example

My first Web page

My first paragraph.

"myFunction ()" > click function myFunction () {[xss_clean] (Date ());}

Write to the console

If your browser supports debugging, you can use the console.log () method to display the JavaScript value in the browser.

Use F12 in the browser to enable debug mode, and click the "Console" menu in the debug window.

My first Web page a = 5 / b = 6 / c = a + b / b / console.log (c)

Screenshot of instance console:

After reading the above, do you have any further understanding of how JavaScript is output? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Elements output content documents paragraphs pages instances browsing methods data code properties console tutorials computers languages controls support differences Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Tech Info Redmi Xiaomi Linux