函数定义

function alert(message?: any): void
function confirm(message?: string): boolean
function prompt(message?: string, _default?: string): string

使用示例

1、提示框 alert

// 没有返回值
alert('你好');

js:常用的3种弹出提示框(alert、confirm、prompt)_提示框

2、确认框 confirm

// 返回 false/true
let res = confirm('确定删除?');
console.log(res);

js:常用的3种弹出提示框(alert、confirm、prompt)_函数定义_02

3、输入框 prompt

// 返回用户输入的值或null, 第二个值为指定的默认值(可选)
var ret = prompt('请输入您的年龄', 23);
console.log(ret);

js:常用的3种弹出提示框(alert、confirm、prompt)_开发语言_03


参考
JavaScript中常用的3种弹出提示框(alert、confirm、prompt)