哪位大神帮忙看看,点了按钮没反应,不知道哪里错了。。

来源:2-7 编程练习

慕前端1323152

2018-05-18 15:25

<!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 new=confirm("是否打开网页");
        if(new==true){
            var win=prompt("确定打开网址");
        }
        if(win!=null){
            window.open(`http://www.imooc.com`,`_blank`,`width=400,height=500,menubar=no,toolbar=no`)
        }
        else
        {document.write("再见");}
        else
        {document.write("再见");}}

写回答 关注

2回答

  • 慕婉清5312678
    2018-05-18 16:08:34

    <!DOCTYPE html>

    <html>


    <head>

    <title> new document </title>

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

    <script type="text/javascript">

    function openWindow() {

    var n = confirm("是否打开网页");

    if (n == true) {

    var win = prompt("确定打开网址");

    if (win != null) {

    window.open(`http://www.imooc.com`, `_blank`, `width=400,height=500,menubar=no,toolbar=no`)

    } else {

    document.write("再见");

    }

    } else {

    document.write("再见")

    }

    }

    </script>

    </head>


    <body>

    <input name="button" type="button" onClick="openWindow()" value="打开新窗口" />

    </body>


    </html>

    这样就行了,new是个指定变量有特定用途,最好不要用来自己设定!

    然后你的问题就是多个功能的大括号逻辑有点混乱,所以导致无法运行!

    慕前端132...

    好的,谢谢

    2018-05-19 10:12:35

    共 1 条回复 >

  • JoeyWongW_
    2018-05-18 15:51:18

    win != null改成win==null,然后弹出来的第二个框中点取消

    慕前端132...

    好的,谢谢

    2018-05-19 10:16:03

    共 1 条回复 >

JavaScript入门篇

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

738651 学习 · 9561 问题

查看课程

相似问题