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

html页面简单的三种对话框如下:

1、alert(),最简单的提示框:

alert("你好!");

2、confirm(),有确认和取消两个按钮:

if(confirm("还有继续吗?")){
    alert("继续");
}else{
    alert("再见");
}

3、prompt(),可以输入信息:

var name = prompt("你的名字是:");
alert("你好," + name);

完整的html代码:

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="content-type" content="text/html; charset=UTF-8">

    <title>对话框测试</title>

    <script>
    	function confirmDialog(){
			if(confirm("还要继续吗?")){
	    		alert("继续");
			}else{
    			alert("再见");
			}
    	}

    	function promptDialog(){
    		var name = prompt("你的名字是:");
			alert("你好," + name);
    	}
    </script>
  </head>

<body>

	对话框测试:

	<div style="margin-top:50px">
		<input type="button" value="alert" onclick="alert('你好!')" />
		<input type="button" value="confirm" onclick="confirmDialog()" />
		<input type="button" value="prompt" onclick="promptDialog()" />
	</div>
</body>
</html>

(原创文章,转载请注明转自Clement-Xu的csdn博客。)

版权声明:本文为原创文章,转载请注明转自Clement-Xu的csdn博客。

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

html页面的简单对话框(alert, confirm, prompt)的相关文章

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()

alert/confirm/prompt 处理

webdriver 中处理JavaScript 所生成的alert.confirm 以及prompt 是很简单的.具体思路是使用switch_to_alert()方法定位到alert/confirm/prompt.然后使用text/accept/dismiss/send_keys 按需进行操做. text 返回alert/confirm/prompt 中的文字信息. accept 点击确认按钮. dismiss 点击取消按钮,如果有的话. send_keys 输入值,这个alert\confir

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:百度的设

【selenium自动化——alert/confirm/prompt 处理】

webdriver 中处理 JavaScript 所生成的 alert.confirm 以及 prompt 是很简单的.具体思路是使用switch_to.alert()方法定位到 alert/confirm/prompt.然后使用 text/accept/dismiss/send_keys 按需进行操做. text 返回 alert/confirm/prompt 中的文字信息.accept 点击确认按钮.dismiss 点击取消按钮,如果有的话.send_keys 输入值,这个 alert\co

9. 处理alert/confirm/prompt

webdriver中处理原生的js alert confirm 以及prompt是很简单的.具体思路是使用switch_to.alert()方法定位到alert/confirm/prompt.然后使用text /accept/dismiss/send_keys按需进行操做 text.返回alert/confirm/prompt中的文字信息 accept.点击确认按钮 dismiss.点击取消按钮,如果有的话 send_keys.向prompt中输入文字 alert.html <html> &l

alert\confirm\prompt

不是所有的弹出框都叫alert,在使用alert方法前,先要识别出到底是不是alert.先认清楚alert长什么样子,下次碰到了,就可以用对应方法解决. alert\confirm\prompt弹出框操作主要方法有: text:获取文本值 accept() :点击"确认" dismiss() :点击"取消"或者叉掉对话框 send_keys() :输入文本值 --仅限于prompt,在alert和confirm上没有输入框 一.认识alert\confirm\pro

alert confirm prompt之间的区别

js当中Window有三个弹出框方法,分别是alert      confirm        prompt alert("弹出警告内容");           只是起到提示或者警示的作用,并没有返回值: confirm("弹出需要确认的内容");     需要用户确认,返回true  /   false; prompt("提示用户输入框需要输入的内容","输入框中默认的内容");          需要用户输入内容,返回用

cefsharp重写默认js弹窗(alert/confirm/prompt)

1.设置js弹窗控制器 webView.JsDialogHandler = this;  //js弹窗控制 2.实现接口方法 public bool OnJSAlert(IWebBrowser browser, string url, string message) { MessageBox.Show(message); return true; //阻止js弹 } public unsafe bool OnJSConfirm(IWebBrowser browser, string url, s

alert() confirm() prompt() 的区别?

alert()是警告消息框,属于BOM中的成员函数,就是window.alert( ); window.alert函数弹出的对话框是模式对话框,用户必须关闭消息框才能继续进行操作;由于js没有输入输出,所以浏览器的window对象提供了两个函数alert和prompt对应output和input; prompt()是提示消息框,用户可以根据提示输入字符串:比如var name = prompt('请输入姓名'),就是新声明一个变量name,用于接收用户输入的值: confirm()是确认消息框,

Selenium处理alert/confirm/prompt提示框

目录 About selenium处理alert提示框 selenium处理confirm提示框 selenium处理prompt提示框 返回上一页 About 回到顶部 重新认识alert首先,不是所有的alert都能叫做alert框.JavaScript中,关于消息提示框的方法有三个(虽然都跟alert差不多): alert(message)方法用于显示带有一条指定消息和一个 OK 按钮的警告框. confirm(message)方法用于显示一个带有指定消息和 OK 及取消按钮的对话框.如果