JS弹出对话框函数alert(),confirm(),prompt()

1,警告消息框alert()

alert 方法有一个参数,即希望对用户显示的文本字符串。该字符串不是 HTML 格式。该消息框提供了一个“确定”按钮让用户关闭该消息框,并且该消息框是模式对话框,也就是说,用户必须先关闭该消息框然后才能继续进行操作。

2,确认消息框confirm()

使用确认消息框可向用户问一个“是-或-否”问题,并且用户可以选择单击“确定”按钮或者单击“取消”按钮。confirm 方法的返回值为 true 或 false。该消息框也是模式对话框:用户必须在响应该对话框(单击一个按钮)将其关闭后,才能进行下一步操作。

3,提示消息框prompt()

提示消息框提供了一个文本字段,用户可以在此字段输入一个答案来响应您的提示。该消息框有一个“确定”按钮和一个“取消”按钮。如果您提供了一个辅助字符串参数,则提示消息框将在文本字段显示该辅助字符串作为默认响应。否则,默认文本为 "<undefined>"。 与alert( ) 和 confirm( ) 方法类似,prompt 方法也将显示一个模式消息框。用户在继续操作之前必须先关闭该消息框 。

4,实例

<html>
<head>
<script type="text/javascript">
    function disp_alert(){
        window.alert("Hello World!");
    }
    function disp_confirm(){
        var truthBeTold = window.confirm("年满18岁请继续!");
        if(truthBeTold){
            window.alert("成人影片!");
        }else{
            window.alert("少儿不宜!");
        }
    }
    function disp_prompt(){
        var name = window.prompt("Please enter your name","");
        if (name!=null && name!=""){
            window.alert("Hello " + name + "!");
        }
    }
</script>
</head>
<body>
<input type="button" onclick="disp_alert()" value="alert button" />
<input type="button" onclick="disp_confirm()" value="confirm button" />
<input type="button" onclick="disp_prompt()" value="Display a prompt box" />
</body>
</html>

  

时间: 2024-07-30 02:52:04

JS弹出对话框函数alert(),confirm(),prompt()的相关文章

js 弹出对话框的方法总结

原文:http://www.cnblogs.com/xiaofengfeng/archive/2012/10/20/2732784.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.o

JS弹出对话框的三种实现方式的意义

最近开始学习JavaScript,最开始讲的就是alert().confirm()和prompt()三种JS弹出对话框.三种弹出对话框分别是警告.确认和提示消息. 第一种警告消息框 (alert)     alert 方法有一个参数,即希望对用户显示的文本字符串.该字符串不是 HTML 格式.该消息框提供了一个"确定"按钮让用户关闭该消息框,并且该消息框是模式对话框,也就是说,用户必须先关闭该消息框然后才能继续进行操作. <script> alert("Hello

js弹出对话框

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>js弹出对话框</title> <script language="javascript"> function alter1() {     alert("我敢保证,你现在用的是演示一

JS弹出对话框的三种方式

JS弹出对话框的三种方式 我们用到了alert()方法.prompt()方法.prompt()方法,都是在网页有一个弹出框,那么就让我们探究一下他们之间的区别: 一.第一种:alert()方法 <html> <head> <title>编写html页面</title> <script language="javascript"> //JavaScript脚本标注 alert("15");//在页面上弹出 &

python selenium 处理JS弹出对话框(六)

在实际系统中,在完成某些操作时会弹出对话框来提示,主要分为"警告消息框","确认消息框","提示消息对话"三种类型的对话框. 1.警告消息框(alert) 警告消息框提供了一个"确定"按钮让用户关闭该消息框,并且该消息框是模式对话框,也就是说用户必须先关闭该消息框然后才能继续进行操作. 2.确认消息框(confirm) 确认消息框向用户提示一个"是与否"问题,用户可以根据选择"确定"按钮

Java Selenium - 几种对话框处理Alert\confirm\prompt

1. Alert , 先用常规办法定位到能触发alert的按钮 , 然后 Alert alert = driver.switchTo().alert(); alert.accept(); 如果alert框确认后,还好连续弹出alert框,继续同样操作,注意延时...不然可能因为太快,出错,坑. Alert alert = driver.switchTo().alert(); alert.accept(); Thread.sleep(1000); alert = driver.switchTo()

html页面的简单对话框(alert, confirm, prompt)

html页面简单的三种对话框如下: 1.alert(),最简单的提示框: alert("你好!"); 2.confirm(),有确认和取消两个按钮: if(confirm("还有继续吗?")){ alert("继续"); }else{ alert("再见"); } 3.prompt(),可以输入信息: var name = prompt("你的名字是:"); alert("你好," +

selenium python (十一)alert/confirm/prompt的处理(js中的弹出框)

webdriver中处理js所生成的alert.confirm以及prompt,采用switch_to_alert()方法定位到alert/confirm/prompt.然后使用text/accept/dismiss/send_keys进行操作 ①text:返回alert/confirm/prompt中的文字信息 ②accept:点击确认按钮 ③dismiss:点击取消按钮 ④send_keys:输入值,这个alert/confirm/prompt没有对话框就不能使用,否则会报错 eg:百度的设

Selenium2学习-040-JavaScript弹出框(alert、confirm、prompt)操作演示实例

弹出框是网页自动化测试常见得操作页面元素之一,常见的JavaScript弹出框有如下三种: 1.alert(message):方法用于显示带有一条指定消息和一个 OK 按钮的警告框.DemoAlert.html 示例代码如下所示: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html&g