【问题标题】:How to alert contents of console.log? [closed]如何提醒console.log的内容? [关闭]
【发布时间】:2013-10-01 13:49:36
【问题描述】:

我想提醒/提示console.log()的内容。

如何提醒/提示 - console.log("I want to eat" + " " + food);? 我试过alert("I want to eat" + " " + food);,但似乎无效。

例如

<script>
var foodDemand = function(food) {

  console.log("I want to eat" + " " + food);

};

foodDemand("Fried Chicken");
</script>

如何提醒/提示 - console.log("I want to eat" + " " + food);? 我试过alert("I want to eat" + " " + food);,但似乎无效。

foodDemand("Fried Chicken"); 在控制台中产生: "I want to eat Fried Chicken"

如何使用prompt();alert(); 获得相同的效果?

【问题讨论】:

  • console.log 更改为 alertprompt 并按预期工作。
  • 和你一样...,将console.log替换为alert,就是这样...
  • 为了迂腐,我也会稍微改变一下字符串:alert("I want to eat " + food);
  • @Andy 或者只是你的单引号:alert('I want to eat ' + food);

标签: javascript alert prompt console.log


【解决方案1】:
   its working for me

 <script>
    var foodDemand = function(food) {

      alert(food);

    };

    foodDemand("Fried Chicken");
    </script>

【讨论】:

    【解决方案2】:

    它应该可以正常工作,正如我可以用jsFiddle 演示的那样

    注意,不需要单独添加空格,这样操作:

    "I want to eat " + food

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-31
      • 1970-01-01
      • 1970-01-01
      • 2013-09-01
      • 2018-05-07
      • 2022-01-17
      • 2012-03-02
      相关资源
      最近更新 更多