Home > Web Front-end > JS Tutorial > body text

JavaScript's three message boxes alert, confirm, and prompt

高洛峰
Release: 2016-12-20 11:56:59
Original
2327 people have browsed it

1. alert is a pop-up warning box. Add n to the text to wrap the text.

2. confirm pops up a confirmation box and returns a Boolean value. This value can be used to determine whether to confirm or cancel when clicking. true means that confirmation was clicked, false means that cancel was clicked.

3. The prompt pops up the input box, click Confirm to return the value in the input box, click Cancel to return null.

The following is a detailed example:

<html>  
<head>  
<script type="text/javascript">  
function show_alert(){  
    alert(&#39;第一行\n第二行&#39;);  
}  
  
function show_confirm(){  
    var result = confirm(&#39;是否删除!&#39;);  
    if(result){  
        alert(&#39;删除成功!&#39;);  
    }else{  
        alert(&#39;不删除!&#39;);  
    }  
}  
  
function show_prompt(){  
    var value = prompt(&#39;输入你的名字:&#39;, &#39;默认名字&#39;);  
    if(value == null){  
        alert(&#39;你取消了输入!&#39;);  
    }else if(value == &#39;&#39;){  
        alert(&#39;姓名输入为空,请重新输入!&#39;);  
        show_prompt();  
    }else{  
        alert(&#39;你好,&#39;+value);  
    }  
}  
</script>  
</head>  
<body>  
<input id="alert_button" type="button" value="alert" onclick="show_alert()" >  
<input id="confirm_button" type="button" value="confirm" onclick="show_confirm()" >  
<input id="prompt_button" type="button" value="prompt" onclick="show_prompt()" >  
</body>  
</html>
Copy after login



For more JavaScript’s three message boxes alert, confirm, and prompt related articles, 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 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!