简体   繁体   English

console.log在symfony应用程序中不起作用

[英]console.log not working inside symfony application

I have this weird problem where console.log does not work inside symfony application. 我有这个奇怪的问题,其中console.log在symfony应用程序中不起作用。 Logging works in other sites though, for example: 但是,日志记录可在其他站点中工作,例如:

http://www.w3schools.com/js/tryit.asp?filename=tryjs_output_console http://www.w3schools.com/js/tryit.asp?filename=tryjs_output_console

Everytime i refresh that page, the console displays correctly: 11 每次刷新该页面时,控制台都会正确显示:11

here is the last part of my code inside the twig template 这是我的树枝模板中代码的最后一部分

{% block javascripts %}
  <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js">
      $(document).ready(function () {
        $('.dropdown-toggle').dropdown();
        console.log(5 + 6);
      });
  </script>
{% endblock %}

The dropdown function works correctly, so javascript is working. 下拉功能正常运行,因此javascript正常运行。 However the console does not display anything. 但是,控制台不显示任何内容。

You need to end your <script> tags that have an src attribute (like you did with jQuery). 您需要结束具有src属性的<script>标记(就像使用jQuery一样)。 When writing JavaScript between tags, they need to be independant to that JavaScript specifically. 在标记之间编写JavaScript时,它们需要专门独立于该JavaScript。 See the documentation for more information. 请参阅文档以获取更多信息。

Specifically from the docs: 特别是从文档:

If a script element has a src attribute specified, it should not have a script embedded inside its tags. 如果脚本元素指定了src属性,则其标签中不应嵌入脚本。

Here's your code updated with the fix: 这是使用修复程序更新的代码:

<script src="//code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script>
    $(document).ready(function () {
        $('.dropdown-toggle').dropdown();
        console.log(5 + 6);
    });
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM