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

求解为什么没成功?

<!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 open=confirm("是否新建网页?");
{var url=prompt("通过输入对话框,确定打开的网址"," http://www.imooc.com");
if(url!=null)
{window.open(url,"_blank",'width=400px,height=500px,menubar=no,toolbar=no');}
else
{alert("再见!");}
}   
else
{alert("再见!");}
}
  </script>
 </head>
 <body>
      <input type="button" value="新窗口打开网站" onclick="openWindow()" />
 </body>
</html>

提问者:慕粉3686312 2016-07-27 19:10

个回答

  • 慕粉3718594
    2016-07-27 19:53:37

    <!DOCTYPE html>

    <html>

     <head>

      <title> new document </title>  

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

    <script type="text/javascript">  

    function openWindow()

    {

    var opena=confirm("是否新建网页?");

               if(opena==true)


      {  

      var url=prompt("通过输入对话框,确定打开的网址","");


      if(url!=null&&name!="")


      {

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

        }


    else


    {

    alert("再见");


    }

    }

    else


    {alert("再见");

    }


    }

      </script> 

     </head> 

     <body> 

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

     </body>

    </html>


    少了加粗部分是上的一个}

  • Wang19961022
    2016-07-27 19:50:46

    <!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 open=confirm("是否新建网页?");

    //加入一个if判断语句

    if(open==true)
    {var url=prompt("通过输入对话框,确定打开的网址"," http://www.imooc.com");
    if(url!=null)
    {window.open(url,"_blank",'width=400px,height=500px,menubar=no,toolbar=no');}
    else
    {alert("再见!");}
    }   
    else
    {alert("再见!");}
    }
      </script> 
     </head> 
     <body> 
          <input type="button" value="新窗口打开网站" onclick="openWindow()" /> 
     </body>
    </html>

  • strawIce
    2016-07-27 19:45:31

    去掉多余的大括号,和最后多余的else就行了

    <!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 open=confirm("是否新建网页?");

      var url=prompt("通过输入对话框,确定打开的网址"," http://www.imooc.com");

    if(url!=null)

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

    else

    {alert("再见!");}

    </script> 

     </head> 

     <body> 

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

     </body>

    </html>