不加prompt为什么不行?

来源:2-7 编程练习

dd小雷子

2016-06-22 00:50

如果不加prompt,下面这样写错在哪里?求指点。

<script type="text/javascript">  

   function openWindow(){

       var mychar=confirm("确定在新窗口打开网站?");    

       if(mychar==true){

       

               window.open('http://www.baidu.com',"_blank",'width=500px height=400px');

           }

           else{

               alert("再见");

           }


       

  </script> 


写回答 关注

2回答

  • 泮池五月风
    2016-06-23 17:36:10
    <!DOCTYPE HTML>
    
    <html>
    
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>函数调用</title>
    
      <script type="text/javascript">
    
       function openWindow(){
    
           var mychar=confirm("确定在新窗口打开网站?");   
    
           if(mychar==true){
    
                   window.open('http://www.baidu.com',"_blank",'width=500px height=400px');
    
               }
    
               else{
    
                   alert("再见");
    
               }
    
          }
    
       </script>
    
    </head>
    
    <body>
    
       <form>
    
          <input type="button"  value="点击我" onclick="openWindow()" /> 
    
       </form>
    
    </body>
    
    </html>

    3个错误。1:var mychar=confirm("确定在新窗口打开网站?");【这里的分号你用的是中文的符号,改为英文的】

                    2:alert("再见");【这里的分号你用的是中文的符号,改为英文的】

                    3:function openWindow(){} 【这里的花括号(})是成对的,你在后面就没了】

    改完后,运行就没问题了。

  • NEONEO
    2016-06-22 01:11:15

    我也是新手一枚,不过你_blank那里应该用''而不是""

    另外少了个  }

JavaScript入门篇

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

741114 学习 · 9865 问题

查看课程

相似问题