window对象的应用(JavaScript)

 window对象的使用(JavaScript)

一、创建警告对话框

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<script type="text/javascript">
			function checkPassword(testObject){
				if(testObject.value.length<8)
				alert("密码长度不能小于8位!");
			}
		</script>
	</head>
	<body>
		请输入密码:<input type="password" onblur="checkPassword(this)">
	</body>
</html>

 显示效果截图

二、创建确认对话框

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			function isConfirm(){
				if(confirm("您确认删除此信息吗?"))
					alert("此信息已删除!");
				else
					alert("已撤销删除!");
			}
		</script>
	</head>
	<body>
		个人信息详情<br>
		<input type="button" value="delete" onclick="isConfirm()" />
	</body>
</html>

显示效果截图

三、创建信息提示对话框

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			var name=prompt("请输入你的名字");
			document.write("你的姓名是:"+name);
		</script>
	</head>
	<body>
	</body>
</html>

显示效果截图

 

 

四、打开指定对话框

(一)

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			window.open("http://www.baidu.com","",
			"toolbar=yes,scroll=yes,height=600,width=1000,resizable=yes,location=yes");
		</script>
	</head>
	<body>
	</body>
</html>

显示效果截图

 

(二)

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			function open_with(){
				window.open("","temp","top=80,left=200,width=300,height=100");
			}
		</script>
	</head>
	<body>
		<form target="temp" action="index.html">
			<input type="submit" value="打开窗口"  onclick="open_with()"/>
		</form>
	</body>
</html>

index.html

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<script type="text/javascript">
			function checkPassword(testObject){
				if(testObject.value.length<8)
				alert("密码长度不能小于8位!");
			}
		</script>
	</head>
	<body>
		请输入密码:<input type="password" onblur="checkPassword(this)">
	</body>
</html>

 

显示效果截图 

五、定时器的使用

(一)

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			function date(){
			var now=new Date();
			document.getElementById('text01').value=now.toLocaleString();
			}
			setInterval("date()",1000);
		</script>
	</head>
	<body>
		<form>
			现在的时间是:<input type="text" id="text01" />
		</form>
	</body>
</html>

显示效果截图

(1)IE浏览器

(2)火狐浏览器

(二)创建和清除计时器

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			var a=0,t;
			function timeCount(){
				document.getElementById('text01').value=a;
				a=a+1;
				t=setTimeout("timeCount()",1000)
			}
		</script>
	</head>
	<body>
		<form>
			<input type="text" id="text01" />
			<input type="button" value="开始计时" onclick="timeCount()"/>
			<input type="button" value="结束计时" onclick="clearTimeout(t)" />
		</form>
	</body>
</html>

显示效果截图 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值