为了账号安全,请及时绑定邮箱和手机立即绑定

不加prompt为什么不行?

如果不加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 回答

<!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(){} 【这里的花括号(})是成对的,你在后面就没了】

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

0 回复 有任何疑惑可以回复我~

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

另外少了个  }

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

不加prompt为什么不行?

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号