【发布时间】:2016-03-14 22:29:06
【问题描述】:
我正在使用 Ben Alman 的 jQuery 油门 - debounce 脚本,当它被触发时,我一直遇到 Uncaught TypeError。
也应该说,我使用 Twitter Bootstrap 作为响应式设计的框架,并且在页面上也有一些同步的 CarouFredSels。
我得到的错误是: Uncaught TypeError: callback.apply is not a function jquery.ba-throttle-debounce.js:149
我查看第 149 行,这是感兴趣的区域:
function wrapper() {
var that = this,
elapsed = +new Date() - last_exec,
args = arguments;
function exec() {
last_exec = +new Date();
callback.apply( that, args ); //LINE 149//
};
function clear() {
timeout_id = undefined;
};
if ( debounce_mode && !timeout_id ) {
exec();
}
timeout_id && clearTimeout( timeout_id );
if ( debounce_mode === undefined && elapsed > delay ) {
exec();
} else if ( no_trailing !== true ) {
timeout_id = setTimeout( debounce_mode ? clear : exec, debounce_mode === undefined ? delay - elapsed : delay );
}
};
我对这个脚本不是很熟悉,因为它在我被要求接手之前就已经到位。当用户点击搜索字段时触发节流脚本,该字段会切换“自动完成”脚本以供稍后实施。
【问题讨论】:
-
如果你要添加一个小提琴,它需要“工作”(如显示你的错误)否则它毫无意义。
-
jfiddle 现在“工作”了。
-
Error: Bootstrap's JavaScript requires jQuery- 你的小提琴甚至不包括你正在使用的 jquery 版本。 -
嗯...结果显示正确...您的浏览器缓存了吗?
-
阅读documentation ;) 是
$.debounce(delay, callback)而不是$.debounce(callback, delay)
标签: jquery twitter-bootstrap caroufredsel typeerror throttling