【问题标题】:jQuery not running locallyjQuery 不在本地运行
【发布时间】:2016-08-12 18:03:33
【问题描述】:

我在 head 标签内声明了以下链接:

<script type="text/javascript" src="javascript/jquery-3.1.0.min.js"></script>
<script type="text/javascript" src="javascript/scripts.js"></script>

以及脚本文件中的以下代码:

$("#person").hover(function() { 
    // trigger the mouseover event
    $("#person-text span").addClass("important-info");
}, function() { 
    // trigger the mouseout event
    $("#person-text span").removeClass("important-info");
});

$(document).ready(function(){
    console.log( "ready!" );
});

我也尝试过通过 Google 和 Microsoft CDN 添加 jQuery 库,但效果不佳。

这是控制台错误的屏幕截图:

【问题讨论】:

  • 有任何错误需要报告吗?
  • 当尝试在 Chrome/Firefox 上预览时,它不会运行。
  • 好的,你在看控制台吗?有没有错误?
  • 尝试将整个代码包装在 document.ready 函数中。
  • @ChristosMaris 那张图片不是我们要找的。在您的浏览器中,按 F12,应该会打开一个框架,并且您应该会看到一个名为“控制台”的选项卡。单击它并刷新您的页面。你看到了什么?

标签: javascript jquery html


【解决方案1】:

几天前我遇到了类似的问题。我将自定义脚本标记移到 HTML 页面的末尾,并且代码有效。它通常发生在 $(document).ready() 函数中。

<script type="text/javascript" src="javascript/scripts.js"></script>

将上述行移到您的 Html 页面的末尾,这应该可以工作。

【讨论】:

  • HTML页面末尾是什么意思?具体在哪里?
  • 首先非常感谢,它成功了。其次,有人知道为什么吗?
  • 无论您使用什么页面,HTML/PHP /ASPX。将其移到
【解决方案2】:

尝试使用$(document).ready(function(){/*your code*/})
并尝试更改您的浏览器控制台是否显示 jQuery 文件的 404 错误

<script type="text/javascript" src="javascript/jquery-3.1.0.min.js"></script>

 <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.0.min.js
"></script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多