我正在创建一个Rails应用程序,并且正在使用readyselector插件来包含页面特定的javascript。
这是readyselector代码。
(function ($) {
var ready = $.fn.ready;
$.fn.ready = function (fn) {
if (this.context === undefined) {
// The $().ready(fn) case.
ready(fn);
} else if (this.selector) {
ready($.proxy(function(){
$(this.selector, this.context).each(fn);
}, this));
} else {
ready($.proxy(function(){
$(this).each(fn);
}, this));
}
}
})(jQuery);
以下是包含在其中的顺序 application.js
//= require jquery
//= require jquery_ujs
//= require plugins/readyselector
//= require jquery-ui
//= require bootstrap
---------- other files
--------
我的一个JavaScript文件像这样开始
jQuery(document).ready(function($) {
var wrapper = $('<div/>').css({ height: 0, width: 0, 'overflow': 'hidden' });
....
....
});
我收到一个错误消息,说$().css
这不是一个函数。但是,如果我使用jQuery
而不是$
代码将正常工作。
当我删除插件时也没有错误。
我究竟做错了什么 ?
准备好将$参数删除到文档中:
此参数的值为0,不再有函数(jQuery的缩写)!
您可以自己调试并查看它。
(function ($) {
var ready = $.fn.ready;
$.fn.ready = function (fn) {
if (this.context === undefined) {
// The $().ready(fn) case.
ready(fn);
} else if (this.selector) {
ready($.proxy(function(){
$(this.selector, this.context).each(fn);
}, this));
} else {
ready($.proxy(function(){
$(this).each(fn);
}, this));
}
}
})(jQuery);
jQuery(document).ready(function() {
var wrapper = $('<div/>').css({ height: 0, width: 0, 'overflow': 'hidden' });
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句