为什么点击取消了以后会输出“要努力了!不准不填,滚回去重新来过!”这样两个内容

来源:2-4 JavaScript-提问(prompt 消息对话框)

嗯是锕梁

2019-01-11 09:35

<!DOCTYPE HTML>

<html>

<head>

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

<title>prompt</title>

  <script type="text/javascript">

  function rec(){

var score; //score变量,用来存储用户输入的成绩值。

score = prompt("请输入您的成绩:")               ;

if(score>=90)

{

  document.write("你很棒!");

}

else if(score>=75)

    {

  document.write("不错吆!");

}

else if(score>=60)

    {

  document.write("要加油!");

    }

    else if(score>=0)

{

       document.write("要努力了!");

}

else (score=null);

{

   document.write("不准不填,滚回去重新来过!");

}

  }

  </script>

</head>

<body>

    <input name="button" type="button" onClick="rec()" value="点击我,对成绩做评价!" />

</body>

</html>


这是我又加了个点击取消的内容,为什么点击取消了以后会输出“要努力了!不准不填,滚回去重新来过!”这样两个答案呢,正确应该怎么做。求教大神

写回答 关注

1回答

  • lamn
    2019-01-11 09:54:45
    已采纳

    <!DOCTYPE HTML>

    <html>

    <head>

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

    <title>prompt</title>

      <script type="text/javascript">

      function rec(){

    var score; //score变量,用来存储用户输入的成绩值。

    score =prompt("请输入你的成绩:");                ;

    if(score>=90)

    {

       document.write("你很棒!");

    }

    else if(score>=75)

        {

       document.write("不错吆!");

    }

    else if(score>=60)

        {

       document.write("要加油!");

        }

        else if(score>=0&&score!=null)

    {

           document.write("要努力了!");

    }

    else 

    {

        document.write("哼不准不填!");

    }

      }

      </script>

    </head>

    <body>

        <input name="button" type="button" onClick="rec()" value="点击我,对成绩做评价!" />

    </body>

    </html>


    河流午后我经... 回复嗯是锕梁

    你的代码里最后一个判断里score=null是个赋值语句不是条件语句

    2019-01-18 09:48:55

    共 2 条回复 >

JavaScript入门篇

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

740768 学习 · 9567 问题

查看课程

相似问题