问答详情
源自:2-7 编程练习

请问这种逻辑哪里错了?一定要用prompt?

<!DOCTYPE html>

<html>

 <head>

  <title> new document </title>  

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

  <script type="text/javascript">  

  function openWindow(){

            var mymessage= confirm("打开新网页?");  

            if(mymessage==ture)

                {function Wopen(){

      window.open("https://hao.360.cn/?wd_xp1","binbin",scrollbars="yes",toolbar="yes", status="yes")

}

    else

    {

        window.close();

    }

  }    

  


       

   

   

  //代码走到这一步就出错了,后面的功能暂时不考虑,求老师解答

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


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


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


   

    

  </script> 

 </head> 

 <body> 

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

 </body>

</html>


提问者:别人在等伞你却在等雨停 2016-11-03 11:12

个回答

  • 慕九州8359721
    2016-11-03 11:49:51
    已采纳

    function openWindow(){

               var open;

               var mymessage= confirm("打开新网页?");  

               if(mymessage){

                open = prompt("请输入网址","http://www.imooc.com");

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

    }else{

            window.close();

        }

     }    

     //代码走到这一步就出错了,后面的功能暂时不考虑,求老师解答

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

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

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

    //建议,你写的代码 格式和语法都有错误,再重新看一看,多练

    </script> 


  • LytZz
    2016-11-03 11:21:42

     if(mymessage==ture)

                    {function Wopen(){

          window.open("https://hao.360.cn/?wd_xp1","binbin",scrollbars="yes",toolbar="yes", status="yes")

    }


    你怎么把函数Wopen()定义在openWindow()函数里面呀

    不能在函数里面再定义函数呀,只能调用