【问题标题】:alert and prompt javascript警报和提示javascript
【发布时间】:2013-03-23 19:28:27
【问题描述】:

浏览器显示“thinksHarry Potter”,“thinks”和“harry”两个词之间没有空格,所以我的伙计们能告诉我该怎么做吗?这是我的代码:

<!DOCTYPE html>
<html>
  <body>
    <button onclick="myFunction()">Try it</button>

    <script>
      function myFunction() {
        var person = prompt("Please enter your name", "Harry Potter");

        if (person != null) {
          alert("thinks" + person);
        }
      }
    </script>
  </body>
</html>

【问题讨论】:

  • alert('thinks ' + person);
  • 这一定是个结局。

标签: javascript alert prompt


【解决方案1】:

在警报消息中的thinks 后面加一个空格

if (person!=null)
  {
    alert('thinks ' + person);
  }
}

JS Fiddle Example

【讨论】:

    【解决方案2】:

    在第一个字符串中放置一个空格字符。

    alert('thinks ' + person);
    

    【讨论】:

      【解决方案3】:

      这很简单,你必须注意在“thinks”之后或“harry”之前没有空格。

      三思而后行:

      alert('thinks' + person);
      

      或在哈利之前:

      var person=prompt("Please enter your name"," Harry Potter");
      

      【讨论】:

      • 你想了想都没加空格!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-21
      • 1970-01-01
      • 2021-10-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多