JavaScript review record - various uses of output
I have studied the output content in JS before, but now I turned it over and looked at it, and it is very unfamiliar. Therefore, in case of memorization, it is best to write it down to impress me most, and it will be much easier to review in the future.
1. Output content document.write
document.write() can be used to directly write content to the HTML output stream and output content directly to the web page.
(1) The output content is directly enclosed in " ".
document.write("Hello World!");
(2) Output content through variables.
var myVar="Hello World!"; document.write(myVar);
(3) Output multiple contents and connect them with numbers.
var myVar="Hello"; document.write(myVar + "World!");
(4) Output HTML tags, and the tags are enclosed in " ".
var myVar="Hello World!"; document.write(myVar + "</br>");
2. Output spaces
Because of the browser display mechanism, manually typed spaces will display multiple consecutive spaces into one space.
(1) Use the output HTMl tag to solve the problem.
document.write(" "+"1"+" "+"23"); //输出结果: 1 23
(2) Use CSS styles to solve it.
document.write("<span style='white-space:pre'>"+" 1 23"+"</span>"); //输出结果: 1 23
3. Warning, alert message dialog box
No other operations can be performed before clicking the "OK" button in the dialog box. The message dialog box can usually be used to debug the program. alert output content, which can be a string or variable, is similar to document.write.
4. Confirmation, confirm message dialog box
The confirm message dialog box is often used to allow users to make choices. Syntax: confirm(str); where str is the text to be displayed in the message dialog box, and the return value is a Boolean value.
var myMessage=confirm("你想学习吗?"); if(myMessage==true){ document.write("想的,好好学习。"); } else{ document.write("不,你想!"); }
note: The user cannot perform other operations before clicking the dialog button.
5. Question, prompt message dialog box
prompt pops up a message dialog box, usually used to ask for some messages that require interaction with the user. The prompt message dialog box includes an OK button, a Cancel button and a text input box. Syntax: prompt(str1,str2); where str1 is the text to be displayed in the message dialog box and cannot be modified, str2 is the content in the text box and can be modified.
var myName=prompt("请输入您的大名:"); if(myName!=Null){ alert("Hello "+myName); } else{ alert("Hello my friend."); }
6. Open a new window. The window.open
open() method can find an existing or newly created browser window. Syntax: window.open([URL],[window name],[parameter string]); among them,
URL: optional parameter, the URL or path of the web page to be displayed in the window, if omitted or If the value of this parameter is an empty string, the window will not display the document.
Window name: The name consists of letters, numbers and _. Names with special meaning: _blank, display the target web page in a new window; _self, display the target web page in the current window; _top, display the target web page in the upper window of the frame web page. Different windows require different names, and there cannot be spaces in the name.
Parameter string:
Parameter | Value | illustrate |
top | Number | Number of pixels from the top of the window to the top of the screen |
left | Number | The number of pixels from the left end of the window to the left end of the screen |
width | Number | Window width |
height | Number | Window height |
menubar | yes,no | Whether the window has a menu |
toolbar | yes,no | Whether the window has a toolbar |
scrollbars | yes,no | Whether the window has scroll bars |
status | yes,no | Whether the window has a status bar |
var myWin=window.open("https://blog.csdn.net/bertZuo"); //将新打开的窗口对象存储在变量myWin中 myWin.close(); //关闭窗口
Related articles:
Summary of various methods of Javascript pop-up windows_javascript skills
Related Video:
JavaScript basic syntax and basic statement video tutorial
The above is the detailed content of JavaScript review record - various uses of output. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...

Explore the implementation of panel drag and drop adjustment function similar to VSCode in the front-end. In front-end development, how to implement VSCode similar to VSCode...
