jQuery $(window).resize不在jQuery插件中触发 [英] jQuery $(window).resize not firing within jQuery plugin

查看:113
本文介绍了jQuery $(window).resize不在jQuery插件中触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义jQuery插件,并在使窗口调整大小功能在该插件中触发时遇到了问题.将其分解为我所掌握的基本知识,无法弄清为什么它不触发:

I've created a custom jQuery plugin and having issues getting the window resize function to fire within the plugin. Broke it down to the basics of what I got, can't figure out why it's not firing:

;(function ( $, window, document, undefined ) {
  $.fn.test = function(options) {
    $(window).resize(function() {
      alert('sdsd');
    });
  };
})(jQuery);

$(function() {
  $('.element').test();
});

推荐答案

在您的情况下,由于未将window传递给函数,因此未定义.

In your case window is undefined because you aren't passing it into the function.

;(function ( $, window, document, undefined ) {
  $.fn.test = function(options) {
    $(window).resize(function() {
      alert('sdsd');
    });
  };
})(jQuery, window, document); //<--- changes here

这篇关于jQuery $(window).resize不在jQuery插件中触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆