不知道哪里代码错了

来源:2-7 编程练习

qq_周东旭_0

2016-03-02 13:26

  function openwindow()
    {
     var open=confirm("是否打开网址?");
     if (open==true)
     {
         var url=prompt("是否打开下列网址?","www.imooc.com");
         if(url!=null)
         {window.open(url,'_blank','width:400px,height:500px','menubar:no,toolbar:no');}
     }
     else
     {alert("over");}
     }
     else{alert("over");}
    }

写回答 关注

9回答

  • lion32
    2016-03-02 15:01:20

    confirm那里返回的是地址,不可能==true,直接在if()里面写返回的变量名就好了

  • StudyMan
    2016-03-02 14:52:25

    <!DOCTYPE html>

    <html>

    <head>

        <title> new document </title>

        <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>

        <script type="text/javascript">

            function openWindow(){

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

                alert("是否打开新窗口");

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

                var openmind = confirm("我将打开对话框?你脚得捏?")

                if(openmind==true)

                {

                    //打开的窗口要求,宽400像素,高500像素,无菜单栏、无工具栏。

                    window.open("http://www.imooc.com/","_blank","width=400,height=500,menubar=no,toolbar=no")

                }

                else{

                    document.write("用户已取消");

                }

            }



        </script>

    </head>

    <body>

    <input type="button" value="新窗口打开网站" onclick="openWindow()" />

    </body>

    </html>


  • 李挺的天空
    2016-03-02 14:32:20

    少了http://

    关于URL,你要再学习一下,没有http://,会默认为本地地址,自然打不开。

      function openwindow()
        {
         var open=confirm("是否打开网址?");
         if (open==true)
         {
             var url=prompt("是否打开下列网址?","www.imooc.com");
             if(url!=null)
             {window.open('+url,'_blank','width:400px,height:500px','menubar:no,toolbar:no');}
         }
         else
         {alert("over");}
         }
         else{alert("over");}
        }


    李挺的天空

    这个编辑器好low啊

    2016-03-02 14:34:05

    共 1 条回复 >

  • 学生_
    2016-03-02 14:31:39

    'width:400px,height:500px','menubar:no,toolbar:no');这里,去掉中间的单引号

  • Hyacinth_zqz
    2016-03-02 14:28:17

    function openwindow()

        {

         var open=confirm("是否打开网址?");

         if (open==true)

         {

             var url=prompt("是否打开下列网址?","http://www.imooc.com");

             if(url!=null)

                 window.open(url,'_blank','width=400,height=500,menubar=no,toolbar=no');

             else

                alert("over");

         }

         else

            alert("over");

        }



  • SkyCanvas
    2016-03-02 13:55:04

     function openwindow()

    Window

  • 鸡蛋面
    2016-03-02 13:53:20

    还有你的地址一定要写http://********

  • 鸡蛋面
    2016-03-02 13:51:53

    function openwindow()

        {

         var open=confirm("是否打开网址?");

         if (open==true)

         {

             var url=prompt("是否打开下列网址?","www.imooc.com");

             if(url!=null)

             {window.open(url,'_blank','width:400px,height:500px','menubar:no,toolbar:no');}

             else

              {alert("over");}

         }

       else{alert("over");}

        }

    你多了个大括号!


    qq_周东旭...

    谢谢谢谢谢!

    2016-03-02 20:00:33

    共 1 条回复 >

  • qq__2043
    2016-03-02 13:47:45

    if...else嵌套有问题,你检查一下

JavaScript入门篇

JavaScript做为一名Web工程师的必备技术,本教程让您快速入门

738650 学习 · 9561 问题

查看课程

相似问题