请问我的代码哪里错了,为什么点按钮没反应呢

来源:1-2 编程练习

杨念

2016-09-11 14:39

<!DOCTYPE HTML>

<html>

<head>

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

<title>系好安全带,准备启航</title>


<script type="text/javascript">

function dui(){

    var a=confirm("准备好了吗?");

        if (a==true)

        {

        document.write("准备好了");    

        }

        

        else

        {

        document.write("没准备好");

        }

    }


</script>

</head>

<body>

<input type="button" value="请点击我" onclick="dui()">

</input>

</body>

</html>


写回答 关注

5回答

  • lhugh
    2016-09-11 14:55:41
    已采纳

    var a=confirm("准备好了吗?");   //此处的分号用的是中文分号

            if (a==true)

            {

            document.write("准备好了");    //此处的分号用的也是中文分号

            }


    以上两处分号改为英文分号就好了

    lhugh 回复杨念

    不客气

    2016-09-11 15:02:39

    共 2 条回复 >

  • qq_小野狗_03903623
    2016-09-11 15:19:45

    不能使用中文分号

  • 慕粉3165875
    2016-09-11 15:10:03

      document.write("没准备好")后面是中文分号,在编码中禁止使用中文符号。

  • 慕粉3165875
    2016-09-11 15:09:59

      document.write("没准备好")后面是中文分号,在编码中禁止使用中文符号。

  • zhj198811013899182
    2016-09-11 14:57:51

    你的    var a=confirm("准备好了吗?")后面的';'以及    document.write("准备好了")后面的';'写成了中文的,用英文状态下的输入法就行了。 

JavaScript进阶篇

本课程从如何插入JS代码开始,带您进入网页动态交互世界

467395 学习 · 21877 问题

查看课程

相似问题