【问题标题】:JQuery issue with addClass methodaddClass 方法的 JQuery 问题
【发布时间】:2014-02-15 01:25:56
【问题描述】:

提前感谢您的帮助。我很难完成 addClass 方法的一个非常简单的案例。我已经阅读了一堆资源,但仍然无法弄清楚。知道为什么这不起作用吗?

<html>
    <head>
        <style>.blueright {color:blue;}</style>
        <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    </head>
    <body>

        <h4 id="test">asdf</h4>
        <script> $("#test").addClass("blueright"); </script>
    </body>
</html>

我做错了什么?再次感谢你! -丹

【问题讨论】:

  • 你是如何打开文件的?
  • 您是否使用file:// url 加载文件 - 从本地文件系统而不是从 Web 服务器加载文件
  • 这段代码在网络上很好,如果你在本地机器上测试你没有给它正确的地址。在其中添加一个 http://,或者等到你在网上找到它就可以了。

标签: jquery addclass


【解决方案1】:

Working Fiddle

您的代码运行良好。


问题在于 jQuery 库加载

尝试脚本网址

<script src="//code.jquery.com/jquery-1.10.2.js"></script>

改变

<script src="http://code.jquery.com/jquery-1.10.2.js"></script>


浏览器将//code.jquery.com/jquery-1.10.2.js 作为

如果您在本地电脑上工作,则需要file://code.jquery.com/jquery-1.10.2.js"

但在服务器上它将它作为http://code.jquery.com/jquery-1.10.2.js"

所以最好使用<script src="http://code.jquery.com/jquery-1.10.2.js"></script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-18
    • 1970-01-01
    • 1970-01-01
    • 2016-04-25
    相关资源
    最近更新 更多