方法一,将js插件cmd模块化(define封装成seajs模块,返回匿名函数,包含插件的源码)。
/**
* Created with JetBrains PhpStorm.
* User: duph
* Date: 13-3-11
* Time: 上午9:24
* To change this template use File | Settings | File Templates.
*/
define(function(require,exports,moudles){
return function(jquery){
(function($) {
$.fn.pri= function() {
alert($("a").attr("href"))
// 代码区域。
};
})(jquery);
}
})
jquery库在总js文件(调用该插件的文件)中加载。通过require("t1/jquery_pligun")($)来传递jquery变量($参数) ,保证了jquery在调用js插件模块之前加载
/**
* Created with JetBrains PhpStorm.
* User: duph
* Date: 13-3-11
* Time: 上午9:40
* To change this template use File | Settings | File Templates.
*/
define(function (require, exports, moudles) {
var $=require("jquery")
require("t1/jquery_pligun")($)
$(document).ready(function () {
$("a").pri()
})
})