Home > php教程 > PHP开发 > body text

The differences and usages of alert(), confirm() and prompt()

高洛峰
Release: 2016-12-20 11:51:07
Original
2192 people have browsed it

Alert message box alert
The alert method has one parameter, which is the text string you want to display to the user. The string is not in HTML format. The message box provides an "OK" button for the user to close the message box, and the message box is a modal dialog box, that is, the user must close the message box before continuing.
window.alert("Welcome! Please press "OK" to continue.");
2. Confirm message box confirm
Use the confirmation message box to ask the user a "yes-or-no" question, and the user can choose to click OK button or click the Cancel button. The return value of the confirm method is true or false. The message box is also a modal dialog box: the user must respond to the dialog box (click a button) to close it before proceeding further.
var truthBeTold = window.confirm("Click "OK" to continue. Click "Cancel" to stop.");
if (truthBeTold) {
window.alert("Welcome to our Web page!");
} else window.alert("Goodbye!");
3. Prompt message box prompt
The prompt message box provides a text field in which the user can enter an answer in response to your prompt. The message box has an "OK" button and a "Cancel" button. If you provide an auxiliary string parameter, the prompt message box will display the auxiliary string in the text field as the default response. Otherwise, the default text is "".
Similar to the alert() and confirm() methods, the prompt method will also display a modal message box. The user must close the message box before continuing
var theResponse = window.prompt("Welcome?","Please enter your name here.");



More alert(), For articles on the difference and usage of confirm() and prompt(), please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!