JavaScript pop-up boxes include: 1. Alert box, which has only one button "OK" and no return value. It is often used to ensure that users can get certain information; 2. Confirmation box, which has two buttons: "OK" and "Cancel" A button, which returns a true or false value, is often used to allow users to verify or accept certain information; 3. Prompt box, which returns the entered message.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
The three dialog boxes of JavaScript are obtained by calling the three methods alert(), confirm() and prompt() of the window object.You can use these dialog boxes to complete js Input and output, implement js code that can interact with users.
Today the editor will briefly introduce the three pop-up dialog boxes in js. The editor will first explain these methods in detail separately, and then compare these methods. Okay, let’s start. Our js journey `(*∩_∩*)′...
First: alert() method
The alert() method is the easiest to use among these three dialog boxes. It can be used to simply and clearly display the text information in the alert() brackets in the dialog box. We call it an alert dialog box. The information to be displayed is placed in brackets, and the dialog box contains a "Confirm" button that the user can simply click to close the dialog box after reading the displayed information. Let's look at an example of using the alert() method. The code is as follows:
Execute the above small example, a dialog box will pop up on the page and the sentence "Shanglian: Ancient trees are dead under the rocks", As shown below:
Then, click the "Confirm" button and then the second dialog box will be displayed and "The girl beside the white water spring is wonderful!", the effect is as follows;
A dialog box pops up on the page and displays the sentence "Shanghai Lien: The ancient trees are dead under the rocks." After clicking the "Confirm" button, the second dialog box is displayed and displayed. "The girl beside the white water spring is wonderful!" Let's analyze this small example:
a. Call the alert() method twice in the
b、在第一个prompt()括号内添加了一段文本信息。
c、name=prompt()一句是将用户在文本框中输入的信息赋给变量name。
alert()、confirm()、prompt()的区别和联系:
警告框alert()
alert是警告框,只有一个按钮“确定”无返回值,警告框经常用于确保用户可以得到某些信息。当警告框出现后,用户需要点击确定按钮才能继续进行操作。语法:alert("文本")。
确认框confirm()
confirm是确认框,两个按钮,确定或者取消,返回true或false。确认框用于使用户可以验证或者接受某些信息。当确认框出现后,用户需要点击确定或者取消按钮才能继续进行操作。如果用户点击确认,那么返回值为 true。如果用户点击取消,那么返回值为 false。语法:confirm("文本")
提示框prompt()
prompt是提示框,返回输入的消息,或者其默认值提示框经常用于提示用户在进入页面前输入某个值。当提示框出现后,用户需要输入某个值,然后点击确认或取消按钮才能继续操纵。如果用户点击确认,那么返回值为输入的值。如果用户点击取消,那么返回值为 null。语法:prompt("文本","默认值")
更多编程相关知识,请访问:编程视频!!
The above is the detailed content of What are the JavaScript pop-up boxes?. For more information, please follow other related articles on the PHP Chinese website!