confirm() 方法用于显示一个带有指定消息和确定及取消按钮的对话框。相对于alert()多了取消按钮。
如果用户点击确定按钮,则 confirm() 返回 true。如果点击取消按钮,则 confirm() 返回 false。
在用户点击确定按钮或取消按钮把对话框关闭之前,它将阻止用户对浏览器的所有输入。在调用 confirm() 时,将暂停对 JavaScript 代码的执行,在用户作出响应之前,不会执行下一条语句。
看两个简单的实例:
XML/HTML代码
- <!DOCTYPE?html?PUBLIC?”-//W3C//DTD?XHTML?1.0?Transitional//EN”?”http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>??
- <html?xmlns=“http://www.w3.org/1999/xhtml”>??
- <head>??
- <meta?http-equiv=“Content-Type”?content=“text/html;?charset=utf-8”?/>??
- <title>无标题文档</title>??
- </head>??
- ??
- <body>??
- 实例2:<br?/>??
- <input?name=“resetmap”?type=“button”?id=“resetmap”?onclick=“{if(confirm(‘您确定要重置地图吗?\n\n重置地图需要花费您100颗普通豆豆!’)){return?true;}return?false;}”?value=“点我”?runat=“server”>??
- <script?type=“text/javascript”>??
- function?disp_confirm() ??
- ??{ ??
- ??var?r=confirm(“显示一个确认框”) ??
- ??if?(r==true) ??
- ????{ ??
- ????document.write(“You?pressed?OK!”) ??
- ????} ??
- ??else ??
- ????{ ??
- ????document.write(“You?pressed?Cancel!”) ??
- ????} ??
- ??} ??
- </script>??
- <br?/>??
- 实例2:<br?/>??
- ??
- <input?type=“button”?onclick=“disp_confirm()”??
- value=“Display?a?confirm?box”?/>??
- </body>??
- </html>??
最新评论
写的挺好的
有没有兴趣翻译 impatient js? https://exploringjs.com/impatient-js/index.html
Flexbox playground is so great!
感谢总结。
awesome!
这个好像很早就看到类似的文章了
比其他的教程好太多了
柯理化讲的好模糊…没懂