Home>Article>Web Front-end> How to implement pop-up window in javascript
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")".
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("你好,我是一个警告框!");
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:
##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. Syntaxwindow.prompt("sometext","defaultvalue");The window.prompt() method can be used directly without the window object. The prompt() method can be used directly. Example:
Rendering:点击按钮查看输入的对话框。
##【Recommended Study:
javascript advanced tutorialThe 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!