Home>Article>Web Front-end> How to implement pop-up window in javascript

How to implement pop-up window in javascript

青灯夜游
青灯夜游 Original
2021-05-19 17:43:20 14665browse

Method: 1. Use alert() to implement the warning box window, the syntax "alert("text");"; 2. Use confirm() to implement the confirmation box window, the syntax "confirm("text")" ;3. Use prompt() to implement the prompt box, the syntax is "prompt("text","default value")".

How to implement pop-up window in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Method 1: Use alert() to implement the warning box window

Alert boxes are often used to ensure that users can get certain information.

When the warning box appears, the user needs to click the OK button to continue the operation.

Syntax

window.alert("sometext");

The window.alert() method can be used directly without the window object. The alert() method can be used directly.

Example:

alert("你好,我是一个警告框!");

How to implement pop-up window in javascript

Method 2: Use the confirm() function to implement the confirmation box window

Confirmation boxes are usually used to verify whether user operations are accepted.

When the confirmation card pops up, the user can click "Confirm" or "Cancel" to confirm the user operation.

When you click "Confirm", the confirmation box returns true. If you click "Cancel", the confirmation box returns false.

Syntax

window.confirm("sometext");

The window.confirm() method can be used directly without the window object, using the confirm() method.

Example:

点击按钮,显示确认框。

Rendering:

How to implement pop-up window in javascript

How to implement pop-up window in javascript

2-How to implement pop-up window in javascript

How to implement pop-up window in javascript

##Method 3: Use the prompt() function to implement the prompt box window

The prompt box is often used to prompt the user to enter something before entering the page. value.

When the prompt box appears, the user needs to enter a certain value and then click the confirm or cancel button to continue the operation.

If the user clicks to confirm, the return value is the entered value. If the user clicks Cancel, the return value is null.

Syntax

window.prompt("sometext","defaultvalue");

The window.prompt() method can be used directly without the window object. The prompt() method can be used directly.

Example:


点击按钮查看输入的对话框。

Rendering:


How to implement pop-up window in javascript

How to implement pop-up window in javascript##【Recommended Study:

javascript advanced tutorial

The above is the detailed content of How to implement pop-up window in javascript. 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