升级的jquery / jquery-ui和现在的event.stopPropagation();不起作用

时间:2018-08-08 20:15:41

标签: jquery jquery-ui

我不确定如何在标题中表达我的问题。我希望这足够清楚。

我将jQuery从很旧的版本升级到了3.3.1,并且还将jQuery-ui升级到了1.12.1。我也有jquery-migrate-3.0.1.min.js。突然以前可以正常工作的代码给我一个错误,我很难找到解决方法。

代码如下:

ABC.Foo = {
  init : function() {
    $('#my-link').toggle(ABC.Foo.on, ABC.Foo.off);
    $('body').click(ABC.Foo.bodyClicked);
  },
  on : function(event) {
    $('#my-panel').show();
    $('#my-id').addClass('selected');
    event.stopPropagation();
  },
  off : function(event) {
    $('#my-panel').hide();
    $('#my-id').removeClass('selected');
    event.stopPropagation();
  },
  bodyClicked : function(event) {
    if ($('#my-id').hasClass('selected')) {
      $("#my-link").trigger('click');
    }
  }
};

这是错误

application.js:34357 Uncaught TypeError: Cannot read property 'stopPropagation' of undefined
at HTMLAnchorElement.off (application.js:34357)
at HTMLAnchorElement.opt.complete (application.js:7268)
at fire (application.js:3269)
at Object.fireWith [as resolveWith] (application.js:3399)
at tick (application.js:7111)
at Function.jQuery.fx.tick (application.js:7437)
at schedule (application.js:6814)

1 个答案:

答案 0 :(得分:0)

toggle(function, function)已过时,并已在jQuery 1.9中删除

https://api.jquery.com/toggle-event/