JavaScript 有三种类型的弹框:警告框、确认框和提示框。
如果要确保信息传递给用户,通常会使用警告框。
当警告框弹出时,用户将需要单击“确定”来继续。
alert("hello world");
alert("hello\nworld"); // \n 会使弹出框换行
如果您希望用户验证或接受某个东西,则通常使用“确认”框。
当确认框弹出时,用户将不得不单击“确定”或“取消”来继续进行。
如果用户单击“确定”,该框返回 true。如果用户单击“取消”,该框返回 false。
var i = confirm(‘hello world‘)
console.log(i);//当点击确定时,打印true,点击取消时,打印false
如果您希望用户在进入页面前输入值,通常会使用提示框。
当提示框弹出时,用户将不得不输入值后单击“确定”或点击“取消”来继续进行。
var j = prompt(‘hello world‘)
console.log(j);
JavaScript 的三种弹出框(alert,confirm,prompt)
原文:https://www.cnblogs.com/qiaoyurensheng/p/12837999.html