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

请问这段代码哪里有问题 点击确定不出现网页

<!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 nw=confirm("是否打开新的窗口?");

        if (nw=="true")

        var nw=prompt('请输入网址','http://www.imooc.com/');

        nw('http://www.imooc.com/','_blank','width=400,height=500,menubar=no,toolbar=no');

        }

        else

        {

            document.write('没有任何操作');

        }

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


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


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

    

    

  </script> 

 </head> 

 <body> 

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

 </body>

</html>


正在回答

6 回答

问题有点多。看下我改的代码,对照下:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title> new document </title>  
    <script type="text/javascript">
        function openwindow(){//函数名要一致,区分大小写。之前你下面的函数名写成openWindow(),跟这个不同。
            var nw=confirm("是否打开新的窗口?");
            if (nw==true){ //true或者false是js的一种数据类型,而'true'是字符串,是不同的,所以用true比较。
                var nw=prompt('请输入网址','http://www.imooc.com/');
                //nw是得到prompt输入的网址。然后用window.open打开新窗口,不是nw。
                window.open(nw,'_blank','width=400,height=500,menubar=no,toolbar=no');
            }//你之前没有把if内容用{}括起来
            else
            {
                document.write('没有任何操作');
            }
        }//函数内容也是要在{}内,

    </script>
</head>
<body>
    <input type="button" value="新窗口打开网站" onclick="openwindow()" />
</body>
</html>

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

慢慢走0 提问者

非常感谢!
2016-01-06 回复 有任何疑惑可以回复我~

有好处错误:

1、true是布尔值,去掉true的引号

2、(nw=true)后面缺少一个{

3、函数最后面少一个}

4、函数名称跟onclick里面写的不一致,应该是openwindow而不是openWindow,注意区分大小写

5、nw('http://www.imooc.com/','_blank','width=400,height=500,menubar=no,toolbar=no'); 需要修改成

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

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

慢慢走0 提问者

非常感谢
2016-01-06 回复 有任何疑惑可以回复我~
<!DOCTYPE html>
<html>
<head>
  <title> new document </title>  
  <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
  <meta charset="UTF-8">  
  <script type="text/javascript">  

    function openWindow()

    {

        var nw=confirm("是否打开新的窗口?");

        if (nw=="true")

        {
          var nw=prompt('请输入网址','http://www.imooc.com/');

        nw('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>

http://img1.sycdn.imooc.com//568cc6ae0001833d09780889.jpg

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

慢慢走0 提问者

非常感谢
2016-01-06 回复 有任何疑惑可以回复我~

 onclick=openWindow() 和 function openwindow()  加下划线大小写你写得不一样


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

慢慢走0 提问者

非常感谢
2016-01-06 回复 有任何疑惑可以回复我~

nw('http://www.imooc.com/','_blank','width=400,height=500,menubar=no,toolbar=no');这句话写错了,应该是window.open(nw,'_blank','width=400,height=500,menubar=no,toolbar=no');

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

慢慢走0 提问者

非常感谢
2016-01-06 回复 有任何疑惑可以回复我~

你都没有调用window.open方法,怎么弹出新页面呢

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

慢慢走0 提问者

非常感谢
2016-01-06 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

请问这段代码哪里有问题 点击确定不出现网页

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信