Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jquery 的引用BUG? #12

Closed
liyoc opened this issue Aug 5, 2013 · 4 comments

Comments

@liyoc
Copy link

commented Aug 5, 2013

被这个问题彻底搞困惑了,接触seajs没几天, 一直被如何引入jquery 而困扰. 我怎么感觉jquery 必须放在 jquery/jquery/1.10.1/jquery.js 才能生效呢?

目录结构很简单, 所有文件都在一个目录中, index.html, application.js, jquery.js

index.html:

<script src="sea.js" ></script>
<script>

seajs.config({
    base: "./",
    alias: {
      "jquery": "jquery.js"   // 换成"jquery/jquery/1.10.1/jquery.js", 并将jquery放入这个位置就没有问题。
    }
});
seajs.use("./application");

</script>

application.js:

define(function(require,exports,module){
var $ = require('jquery');
console.log($("#xxx").html());
});

jquery.js 来自 seajs-master example/sea-modules/jquery/jquery/1.10.1/jquery.js

错误是: TypeError: $ is not a function,
debug seajs.cache
jquery 其实已经被加载进来了。。。
但是发现还有一个 http://localhost:8080/plugins/seajs/mktry/jquery/jquery/1.10.1/jquery.js
这个就不知道从哪里来的了。。。

期待您的回复 :)

@afc163

This comment has been minimized.

Copy link
Member

commented Aug 5, 2013

因为 spmjs 上封装的 jquery 是加入了完整 id 的文件。

    if ( typeof define === "function" ) {
        define("jquery/jquery/1.10.1/jquery-debug", [], function () { return jQuery; } );
    }

在 seajs 中,文件的路径和 id 必须匹配,否则无法读取到模块。seajs/seajs#438

@lifesinger

This comment has been minimized.

Copy link
Member

commented Aug 5, 2013

文件路径要和 id 匹配。可以理解将 id 理解为旅馆的房间号,不要进错房间,否则其他人就找不到你了。

@shrek82

This comment has been minimized.

Copy link

commented Sep 17, 2013

谢谢,问题解决了。grunt build 之后的文件id和使用的路径一样就行了。完美了!

@youngwind

This comment has been minimized.

Copy link

commented Mar 18, 2016

谢谢!!被这个问题坑了大半个小时!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.