引用了一个插件,里面的一个JS文件导致整个网页的链接都不能跳转了,希望大牛来帮忙解决一下?

**以下是js文件的全部代码**

(function ($) {
  'use strict';

  var defaults = {};

  function Menu (element, options) {
    this.$el = $(element);
    this.opt = $.extend(true, {}, defaults, options);

    this.init(this);
  }

  Menu.prototype = {
    init: function (self) {
      $(document).on('click', function (e) {
        var $target = $(e.target);

        if ($target.closest(self.$el.data('menu-toggle'))[0]) {
          $target = $target.closest(self.$el.data('menu-toggle'));

          self.$el
            .css(self.calcPosition($target))
            .toggleClass('show');

        } else if (!$target.closest(self.$el)[0]){
          self.$el.removeClass('show');
        }
        e.preventDefault();
      });
    },

    calcPosition: function ($target) {
      var windowWidth, targetOffset, position;

      windowWidth = $(window).width();
      targetOffset = $target.offset();

      position = {
        top: targetOffset.top + ($target.outerHeight() / 4)
      };

      if (targetOffset.left > windowWidth / 4) {
        this.$el
          .addClass('menu--right')
          .removeClass('menu--left');

        position.right = (windowWidth - targetOffset.left) - ($target.outerWidth() / 4);
        position.left = 'auto';
      } else {
        this.$el
          .addClass('menu--left')
          .removeClass('menu--right');

        position.left = targetOffset.left + ($target.outerWidth() / 4);
        position.right = 'auto';
      }

      return position;
    }
  };

  $.fn.menu = function (options) {
    return this.each(function() {
      if (!$.data(this, 'menu')) {
        $.data(this, 'menu', new Menu(this, options));
      }
    });
  };
})(jQuery);
阅读 1.8k
1 个回答
e.preventDefault(); //阻止了跳转了
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题