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('第一行\n第二行'); } function show_confirm(){ var result = confirm('是否删除!'); if(result){ alert('删除成功!'); }else{ alert('不删除!'); } } function show_prompt(){ var value = prompt('输入你的名字:', '默认名字'); if(value == null){ alert('你取消了输入!'); }else if(value == ''){ alert('姓名输入为空,请重新输入!'); show_prompt(); }else{ alert('你好,'+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>
For more JavaScript’s three message boxes alert, confirm, and prompt related articles, please pay attention to the PHP Chinese website!