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 Comments: A Guide to Using // and /* */JavaScript Comments: A Guide to Using // and /* */May 13, 2025 pm 03:49 PM

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

Python vs. JavaScript: A Comparative Analysis for DevelopersPython vs. JavaScript: A Comparative Analysis for DevelopersMay 09, 2025 am 12:22 AM

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Python vs. JavaScript: Choosing the Right Tool for the JobPython vs. JavaScript: Choosing the Right Tool for the JobMay 08, 2025 am 12:10 AM

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript: Understanding the Strengths of EachPython and JavaScript: Understanding the Strengths of EachMay 06, 2025 am 12:15 AM

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScript's Core: Is It Built on C or C  ?JavaScript's Core: Is It Built on C or C ?May 05, 2025 am 12:07 AM

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript Applications: From Front-End to Back-EndJavaScript Applications: From Front-End to Back-EndMay 04, 2025 am 12:12 AM

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Python vs. JavaScript: Which Language Should You Learn?Python vs. JavaScript: Which Language Should You Learn?May 03, 2025 am 12:10 AM

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

JavaScript Frameworks: Powering Modern Web DevelopmentJavaScript Frameworks: Powering Modern Web DevelopmentMay 02, 2025 am 12:04 AM

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

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 Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool