【发布时间】:2012-10-03 02:57:13
【问题描述】:
我正在创建一个与 Bootstrap 交互的 jQuery 插件,当我在 jQuery 元素上调用该函数时出现以下错误:
Uncaught TypeError: Object [object Window] has no method 'each'
这是有问题的 JavaScript:
!function ($) {
$.fn.alertAutoClose = function (interval) {
setTimeout(function () {
return $(this).each(function () {
$(this).hide();
});
}, interval);
}(window.jQuery);
这是插件的触发方式:
$(".alert").alertAutoClose(1000);
这是页面上的 HTML:
<div class="alert fade in">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Warning!</strong> Best check yo self, you're not looking too good.
</div>
【问题讨论】:
标签: javascript jquery plugins window each