search
HomeWeb Front-endJS TutorialJavaScript 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=&#39;white-space:pre&#39;>"+"  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
7. Close the window, window.close
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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
JavaScript in Action: Real-World Examples and ProjectsJavaScript in Action: Real-World Examples and ProjectsApr 19, 2025 am 12:13 AM

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

JavaScript and the Web: Core Functionality and Use CasesJavaScript and the Web: Core Functionality and Use CasesApr 18, 2025 am 12:19 AM

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding the JavaScript Engine: Implementation DetailsUnderstanding the JavaScript Engine: Implementation DetailsApr 17, 2025 am 12:05 AM

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python vs. JavaScript: The Learning Curve and Ease of UsePython vs. JavaScript: The Learning Curve and Ease of UseApr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python vs. JavaScript: Community, Libraries, and ResourcesPython vs. JavaScript: Community, Libraries, and ResourcesApr 15, 2025 am 12:16 AM

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

From C/C   to JavaScript: How It All WorksFrom C/C to JavaScript: How It All WorksApr 14, 2025 am 12:05 AM

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

JavaScript Engines: Comparing ImplementationsJavaScript Engines: Comparing ImplementationsApr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Beyond the Browser: JavaScript in the Real WorldBeyond the Browser: JavaScript in the Real WorldApr 12, 2025 am 12:06 AM

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.