Javascript 基础编程练习一

Javascript 基础互动编程,这篇练习结合了function 函数名(), onclick 时间, prompt输入窗口, window.open和confirm窗口,

任务

1、新窗口打开时弹出确认框,是否打开

提示: 使用 if 判断确认框是否点击了确定,如点击弹出输入对话框,否则没有任何操作。

2、通过输入对话框,确定打开的网址,默认为 http://www.baidu.com/

3、打开的窗口要求,宽800像素,高600像素,无菜单栏、无工具栏。

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <title> new document </title>
 5     <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
 6     <script type="text/javascript">
 7         function openWindow(){
 8             var mycon=confirm("请问你是否要打开");// 新窗口打开时弹出确认框,是否打开
 9             if(mycon==true){
10                 var mypro=prompt("请输入你要打开的网址");// 通过输入对话框,确定打开的网址,默认为 http://www.cnblogs.com/
11                 if(mypro!=null){
12                     window.open(mypro,"_blank","width=800,height=600,menubar=no,toolbar=no");
13                 }else{
14                     window.open("http://www.cnblogs.com/","_blank","width=800,height=600,menubar=no,toolbar=no");
15                     //打开的窗口要求,宽800像素,高600像素,无菜单栏、无工具栏。
16                 }
17             }
18         }
19     </script>
20 </head>
21 <body>
22 <input type="button" value="新窗口打开网站" onclick="openWindow()" />
23 </body>
24 </html>

 

posted @ 2016-02-18 01:31  BearNoBug  阅读(275)  评论(0编辑  收藏  举报