【问题标题】:head.js and jQuery issues in Chrome / Firefox 5Chrome / Firefox 5 中的 head.js 和 jQuery 问题
【发布时间】:2011-07-08 01:37:20
【问题描述】:

所以页面是这样渲染的:

<!DOCTYPE html>
<html>

<head>
  <script>

   head.js("js/jquery.js",
           "js/jquery.autocomplete.js");

  </script>
</head>

<body>

  ...
  stuff here
  ...

  <script>

    jQuery(document).ready(function($){  // fail...

      $('body').removeClass('no-jquery');
      // ...

    });
  </script>
</body>
</html>

脚本似乎在 Opera 中加载,但在 Firefox 5 和 Chrome 中(不知道版本,因为它每天都在变化)我收到错误:

jQuery is not defined
[Break On This Error] jQuery(document).ready(function($){ 

所以我猜 jquery 在这些浏览器中并没有真正由 head.js 加载?还是我做错了什么?


jsfiddle: http://jsfiddle.net/LDUUd/

【问题讨论】:

    标签: javascript jquery html document head.js


    【解决方案1】:

    尝试切换到head.ready() 而不是jQuery.ready()

    【讨论】:

    • 或者加载你自己的脚本,而不是内联,而是通过 HeadJS 作为一个单独的文件。
    • 然后我得到head(document) is undefined...
    • 有事,你能发个 jsfiddle 吗?
    • 哦,你不需要head(document)。就说head.ready(function() {...;见这里:headjs.com/#usage
    • 我终于让它工作了,但只有当我在 head.ready 函数中使用 jQuery 而不是 $ 时才有效。如果我使用 $ 我会得到一个错误:$ is not a function
    【解决方案2】:

    这是example of it working - 这是你的吗?

    【讨论】:

      【解决方案3】:

      你打电话给head.js() 没有

      <!-- assuming it's in the same directory as the page -->
      <script src="head.min.js"></script>
      

      首先。

      【讨论】:

      • 我也有,只是忘记在上面的代码中提到了.. (head.load.min.js)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多