Javascript 错误:'jQuery 未定义'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3590711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 05:20:40  来源:igfitidea点击:

Error: 'jQuery is not defined'

javascriptjqueryinternet-explorer

提问by michele

I have written a script with jQuery. It works with Firefox and GoogleChrome. Only with IE I have this error returned:

我用 jQuery 编写了一个脚本。它适用于 Firefox 和 GoogleChrome。只有在 IE 中,我才会返回此错误:

'jQuery' is not defined jquery-ui-1.8.4.custom.min.js, Row 10 Character 1

'jQuery' 未定义 jquery-ui-1.8.4.custom.min.js, Row 10 Character 1

This is the head of my page:

这是我页面的头部:

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Contattaci - TheItalianBrand.com</title>
    <script type="text/javascript" src="lib/jquery.js"></script>
    <script type="text/javascript" src="lib/js/jquery-ui-1.8.4.custom.min.js"></script>
    <link type="text/css" href="lib/css/smoothness/jquery-ui-1.8.4.custom.css" rel="stylesheet" /> 
    <script type="application/javascript">
       $(function(){



    $('#dialog_link, ul#icons li').hover(
     function() { $(this).addClass('ui-state-hover'); }, 
     function() { $(this).removeClass('ui-state-hover'); }
    );

    $('input').change(function() {
      validate();
    });
    $('input').keydown(function() {
      validate();
    });
    $('textarea').change(function() {
      validate();
    });
    $('textarea').keydown(function() {
      validate();
    });
   });
   </script>
   </head>

What can I do?

我能做什么?

采纳答案by vol7ron

  1. Don't use application/javascript, change to text/javascript

  2. Check the path of jquery
    is your jquery in lib/js/, or just lib/?

  3. Make sure your lib directory is relative to the calling page
    You may have meant /lib/jquery.js(the slash in the beginning makes a difference)

  1. 不使用application/javascript,改为text/javascript

  2. 检查jquery的路径
    是你的jquery在lib/js/,还是只是lib/

  3. 确保你的 lib 目录是相对于调用页面
    你的意思/lib/jquery.js(开头的斜杠有所不同)

回答by Pointy

You're importing the jQuery UI library from lib/js, but jQuery itself from lib. I suspect that your copy of the jQuery library is also in lib/jsand that you're just not getting it due to that incorrect path. Of course, that would mean that it's not actually working in Firefox or Chrome or any other browser, but it could be that they're just less strident about error reporting so you're not noticing.

您正在从 导入 jQuery UI 库lib/js,但 jQuery 本身是从lib. 我怀疑您的 jQuery 库副本也在其中,lib/js并且由于路径不正确而您没有得到它。当然,这意味着它实际上不适用于 Firefox 或 Chrome 或任何其他浏览器,但也可能是它们对错误报告不那么尖锐,因此您没有注意到。

The Firefox "TamperData" plugin is really handy for tracking HTTP requests on page loads.

Firefox 的“TamperData”插件对于跟踪页面加载时的 HTTP 请求非常方便。

回答by Sagar

You have to check sequence of added jQuery, and adding jQuery library in proper sequence

您必须检查添加的 jQuery 的顺序,并按正确的顺序添加 jQuery 库