HeadJS和jQuery的用法 [英] HeadJS and jQuery Usage

查看:83
本文介绍了HeadJS和jQuery的用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用 http://headjs.com 已有一段时间,但我还没有这样做,因为我可以完全了解有限的文档和样本.如果您可以使用一些jQuery来提供HeadJS的示例,那就太好了.

Trying to use http://headjs.com for a while now but I haven't still because I can't fully understand the limited documentation and samples. If you can give examples of HeadJS with some jQuery that would be great.

目前,这就是我所拥有的:

Currently, this is what I have:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Title</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
</head>
<body>
.....
.....
<script src="js/jQuery.plugins.1.js"></script>
<script src="js/jQuery.plugins.2.js"></script>
<!--
    Below are inline and cannot be a separate JS
    file because of CMS and templating limitation
//-->
<script>
jQuery.noConflict();
jQuery(document).ready(function($) {
    $('.class').someEffect();
    // Too many more code here
});
</script>
<!-- End inline scripts //-->
</body>
</html>

我的问题:

  1. 如果我要使用HeadJS,现在应该在哪里放置 jQuery.noConflict(); ?还是即使我使用另一个JS库也不会有更多冲突?
  2. 将我的内联脚本放在 head.ready()中的什么位置? " $ "符号不会与其他库产生任何冲突吗?
  1. If I'll use HeadJS, where should I put the jQuery.noConflict(); now? Or will there be no more conflicts even if I'll use another JS library?
  2. Where to put my inline scripts, in head.ready()? Do the the '$' sign will not cause any conflicts with other libraries?

谢谢.

推荐答案

我认为您缺少Head JS的要点.这是您的<head>元素的外观:

I think you're missing the point of Head JS. Here's what your <head> element should look like:

<head>
    <meta charset="utf-8" />
    <title>Title</title>
    <script src="path/to/head.js"></script>

    <script>
    // files are loaded in parallel and executed in order they arrive
    head.js('https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js')
        .js('path/to/other/external.js'),
        .js('and/so/on');

    // Call a function after all scripts have been loaded and the document is scriptable
    head.ready(function ()
    {
        jQuery.noConflict();

        // do your inline stuff with $ (Prototype, not jQuery)
    });
    </script>
</head>

这篇关于HeadJS和jQuery的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆