Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法将Jquery与Symfony一起使用_Javascript_Jquery_Symfony - Fatal编程技术网

Javascript 无法将Jquery与Symfony一起使用

Javascript 无法将Jquery与Symfony一起使用,javascript,jquery,symfony,Javascript,Jquery,Symfony,我没有成功地将Jquery与Symfony一起使用。 有关信息,我使用谷歌提供的Jquery链接 在我的小树枝文件中,我有以下几行: <!DOCTYPE html> <html> <head> <title>my title</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5

我没有成功地将Jquery与Symfony一起使用。 有关信息,我使用谷歌提供的Jquery链接

在我的小树枝文件中,我有以下几行:

<!DOCTYPE html>
<html>
  <head>
     <title>my title</title>

     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
     <script src="{{ asset('/js/myjsfile.js') }}" type="text/javascript"></script>  

  </head>

  <body>
     <string class="changecolor red">HELLO<string>
  </body>

</html>

我的css文件工作正常,所以我没有把它放在这里(只是.blue{color:blue};)

您没有关闭括号。您的JavaScript代码应如下所示:

 $(document).ready(function(){ 
        $(".changecolor").mouseenter(function(){
            $(this).addClass("blue");
        });
        $(".changecolor").mouseleave(function(){
            $(this).removeClass("blue");
            $(this).addClass("red");
        });
    });

为什么要使用这么旧的jQuery版本?为什么不使用CSS
:hover
选择器来实现此效果?

谢谢marian0。实际上,我从未将Jquery与Symfony一起使用过,我认为问题不在javascript代码中,而在twig文档中。(到目前为止,还没有将其与资产函数一起导入,这有点混乱)。至于css:hover选择器,我的jquery代码只是尝试将jquery与symfony一起使用。只是想做一个简单的代码(但我还是忘记了括号!太糟糕了。Jquery版本对我来说很好…但可能需要升级。另一个问题:为什么这么多人似乎使用Symfony的Jquery捆绑包,而google提供了一个很好的在线API。(在我看来,使用Php而不使用Symfony的人大多使用谷歌提供的Jquery。)
 $(document).ready(function(){ 
        $(".changecolor").mouseenter(function(){
            $(this).addClass("blue");
        });
        $(".changecolor").mouseleave(function(){
            $(this).removeClass("blue");
            $(this).addClass("red");
        });
    });