窗口alert()方法用于显示警报框。它显示指定的消息以及“确定”按钮,通常用于确保信息通过用户。它返回一个字符串,该字符串表示要在警报框中显示的文本。
用法:
alert(message)
以下示例程序旨在说明窗口alert()方法:
显示警报框。
Window alert() Method in HTML
h1 {
color:green;
}
h2 {
font-family:Impact;
}
body {
text-align:center;
}
GeeksforGeeks
Window alert() Method
For displaying the alert message, double
click the "Show Alert Message" button:
Show Alert Message
function myalert() {
alert("Welcome to GeeksforGeeks.\n " +
"It is the best portal for computer" +
"science enthusiasts!");
}
输出:
单击按钮后
支持的浏览器:下面列出了Window alert()方法支持的浏览器:
谷歌浏览器
IE浏览器
火狐浏览器
Opera
苹果浏览器