javascript入门篇2-7编程练习中程序结果显示页面错误,但代码找不出错

来源:2-7 编程练习

CQ_blue

2016-05-08 21:14

  <script type="text/javascript">  
    function openWindow(){
    // 新窗口打开时弹出确认框,是否打开
        var a=confirm("是否打开输入对话框");
    // 通过输入对话框,确定打开的网址,默认为 http://www.imooc.com/
        if(a==true){
            var b=prompt("请输入你要打开的网址:","http://www.imooc.com/")
            if(b!=null){
                window.open('b','width=400','height=500','menubar=no','toolbar=no')
            }
            else{
                window.open('http://www.imooc.com','height=500','menubar=no','toolbar=no')
            }
            
        }
    }
    //打开的窗口要求,宽400像素,高500像素,无菜单栏、无工具栏。
  </script>
为何我如上的代码,打开imooc网站显示的却是"http://www.imooc.com/error/noexists"错误页面而不是慕课网正常的首页


写回答 关注

3回答

  • qq_昼绽_0
    2016-05-10 00:54:23
    已采纳

     window.open('b','width=400','height=500','menubar=no','toolbar=no')改为

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

    CQ_blu...

    谢谢呐,又学到了细节

    2016-05-10 19:33:03

    共 1 条回复 >

  • 雨穆
    2016-05-08 21:52:18

    ==true这里一个=就可以了吧

    CQ_blu...

    谢谢你的回答呐,不过,if(a==true)和if(a=true)是两个效果哦。==true是判断a是否为true,而=true是给a赋为true的值,这样赋值后不论前面a的值为true还是为false,后面都是为true,这样就会出现使confirm的取消功能无效的现象哦。 不过还是谢谢你呐^_^

    2016-05-10 19:43:17

    共 1 条回复 >

  • 叩首问路
    2016-05-08 21:44:26

    if(a==true)中的true删掉, 不然会导致取消功能失效。

    应该为:if(a)这样就可以。

    if(b!=null){

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

                }

                else{

                    window.open('http://www.imooc.com','height=500','menubar=no','toolbar=no')

                }

    这里的判定也删掉, 直接在后面

    写上:

    if(a==true){

                var b=prompt("请输入你要打开的网址:","http://www.imooc.com/");

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

    叩首问路

    这里出错了, 要把==true删了。 if(a){ var b=prompt("请输入你要打开的网址:","http://www.imooc.com/"); window.open(b,'_blank','width=400,height=500,menubar=no,toolbar=no'); 2秒前

    2016-05-08 21:45:40

    共 2 条回复 >

JavaScript入门篇

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

741104 学习 · 9859 问题

查看课程

相似问题