未捕获的ReferenceError:未定义jQuery

时间:2022-05-28 19:50:33

I am getting this error only in chrome for superfish drop down menu. It works fine in Firefox, and IE. It does not work in Chrome. The menu instead of being horizontal list itself Vertical. domain name of clients actual site has been changed below for confidentiality

我只在chrome中为superfish下拉菜单收到此错误。它在Firefox和IE中运行良好。它在Chrome中不起作用。菜单而不是水平列表本身垂直。客户实际网站的域名已在下面更改为保密

<script type="text/javascript" src="http://www.domainname.com/js/jquery.js"></script>
<script type="text/javascript" src="http://www.domainname.com/js/superfish.js"></script>
<script type="text/javascript" src="http://www.domainname.com/js/hoverIntent.js"></script>
<script type="text/javascript">
    // initialise plugins
jQuery(function(){
     jQuery('ul.sf-menu').superfish();
    });
</script>

I have even changed it to the following and does not work:

我甚至将其更改为以下内容并且不起作用:

    <script type="text/javascript">
         $(document).ready(function(){
            $('ul.sf-menu').superfish();
         })
    </script>

I looked at the view source and it is referencing two header files. This could be causing the error. I am using magento. The menu is working on all pages of the site except the one page checkout.

我查看了视图源,它引用了两个头文件。这可能导致错误。我正在使用magento。菜单正在网站的所有页面上工作,除了一页结帐。

Fixed! read below will post as answer when it lets me in 7 hrs

固定!下面的内容将在7小时内发布时作为答案发布

The issue was not with the javascript itself, but with the css for the superfish menu. The developer who designed the layout and coded the template listed the stylesheet for the superfish menu as:

问题不在于javascript本身,而在于超级鱼菜单的css。设计布局并编码模板的开发人员列出了superfish菜单的样式表:

    <link rel="stylesheet" type="text/css" href="http://www.domainname.com/css/superfish.css" media="screen">

After removing the "http://www.domainname.com" and leaving it as "/css/superfish.css" it fixed the menu.

删除“http://www.domainname.com”并将其保留为“/css/superfish.css”后,修复了菜单。

1 个解决方案

#1


6  

The only reasons trying to use the symbol jQuery like that would cause a ReferenceError would be:

尝试使用符号jQuery的唯一原因会导致ReferenceError:

  1. If the script include for jQuery failed. Check your console for 404s and the like.

    如果脚本包含jQuery失败。检查您的控制台是否有404等。

  2. If one of the later scripts actually deletes the jQuery window property, e.g.:

    如果后面的一个脚本实际上删除了jQuery窗口属性,例如:

    delete window.jQuery;
    

    Just setting jQuery to undefined (perhaps via noConflict) wouldn't cause a ReferenceError, you'd get undefined is not a function or similar. But if you actually delete the property, then you would. (Except on IE, which won't let you delete properties from the window object.)

    只是将jQuery设置为undefined(可能是通过noConflict)不会导致ReferenceError,您将得到undefined不是函数或类似函数。但如果你真的删除了该属性,那么你会。 (在IE上除外,它不允许您从窗口对象中删除属性。)

#1


6  

The only reasons trying to use the symbol jQuery like that would cause a ReferenceError would be:

尝试使用符号jQuery的唯一原因会导致ReferenceError:

  1. If the script include for jQuery failed. Check your console for 404s and the like.

    如果脚本包含jQuery失败。检查您的控制台是否有404等。

  2. If one of the later scripts actually deletes the jQuery window property, e.g.:

    如果后面的一个脚本实际上删除了jQuery窗口属性,例如:

    delete window.jQuery;
    

    Just setting jQuery to undefined (perhaps via noConflict) wouldn't cause a ReferenceError, you'd get undefined is not a function or similar. But if you actually delete the property, then you would. (Except on IE, which won't let you delete properties from the window object.)

    只是将jQuery设置为undefined(可能是通过noConflict)不会导致ReferenceError,您将得到undefined不是函数或类似函数。但如果你真的删除了该属性,那么你会。 (在IE上除外,它不允许您从窗口对象中删除属性。)