Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the ways to output data in JavaScript

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "what are the ways of outputting data in JavaScript". The editor shows you the operation process through an actual case. The method of operation is simple, fast and practical. I hope this article "what are the ways to output data in JavaScript" can help you solve the problem.

Preface

In JavaScript, unlike languages such as Java, it does not have any printing or output methods, usually using the following four ways to output data.

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

Use [xss_clean] () to write content to an HTML document

Use innerHTML to write to HTML elements

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

The following uses them to show an example.

Window.alert ()

Create a new HTML file and write the following code in VSCode.

Window.alert ()

Pop-up display

Window.alert ("this is a pop-up test!")

Then open the above file with a browser, and the following pop-up window will be displayed when you open it. Click OK to close the pop-up window, and then display the content in the web page.

[xss_clean] () [xss_clean] ()

Write to HTML document

[xss_clean] (Date ())

After you create a new HTML file and write the above content, the browser opens and the page displays the following content. You can see that the current time was successfully written with [xss_clean] (). It is important to note, however, that if [xss_clean] () is loaded at the same time as other content before the content is loaded, it can be displayed with other content. However, if you execute [xss_clean] () after the page content has finished loading, then the content previously loaded on the page will be overwritten by the written content.

[xss_clean] ()

Write to HTML document

Click to modify the above function changeContext () {document.getElementById ("inner") [xss_clean] = "modified content";}

Before and after modification

Console.log ()

To use the console.log () method, you need our browser to support debugging, and it is generally recommended to use Chrome. Then use the F12 shortcut to turn on debug mode and switch to the Console menu in the debug window. I use Edge here, so the console is displayed, which is mainly based on your own preferences for browser choice, but generally more recommended Chrome.

Console.log

Browser debug mode view

Var num1 = 11; var num2 = 10; console.log (num1 + num2)

This is the end of the content about "what are the ways to output data in JavaScript". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report