张贤健的个人网站

很宅,没有朋友约又不愿意一个人待在家;不会修电脑;游戏技能点停留在连连看前几关;不会把技术挂在嘴边;不爱穿格子衬衫;没能力轻易开发各种软件。我不是大神,只是程序员中的小学生!

window对象常用方法

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>window对象方法</title>
 6 <script>
 7 window.onload=function(){
 8 //打开一个新的窗口,并赋值给一个变量
 9     subWindow=window.open("http://www.baidu.com","name","height=200,width=300");//我在前面没有加var,他变成了全局变量。
10     setTimeout('location()',1800);
11     setTimeout('CloseW();',4000);//定时,2秒后,执行CloseW函数
12 }
13 function CloseW(){
14     subWindow.close();
15     //alert()方法也是window对象的方法,只不过window可以省略不写
16     window.alert('弹出一个提示框');
17     var bool=window.confirm('您确定要删除该条数据么?');//confirm方法,用户点击是放回ture,点击取消返回false。
18     if(bool)
19         alert('您的数据删除成功!');
20     else
21         alert('您已取消删除数据!');
22     //实现页面跳转
23     var answer=window.prompt("你在哪里读书",'ahnu');//返回null或用户输入的字符串值(非空)
24     if(answer)
25         alert(answer);
26     else
27         alert('您输入的字符串为空');
28     
29     
30 }
31 function location(){
32     subWindow.location.href="http://www.anshida.net";
33 }
34 </script>
35 </head>
36 <body>
37 <span id="e">hehe</span>
38 </body>
39 </html>

网页实例:请点我

posted @ 2016-04-21 19:24  张贤健  阅读(779)  评论(0编辑  收藏  举报