简体   繁体   中英

JQuery Plugin Too Much Recursion on this.each

Why am I getting too much recursion on a jQuery plugin this.each iteration?

(function($) {
  $.fn.selectableList = function(options) {
    return this.each(function() {
      var $this = $(this);
      $this.elem = $this.children('li').click(onClick);
    });
    function onClick() {
      //do something
    }
  }
})(jQuery);

Try just:

$(this).find('li').click(onClick);

Instead of the 2 lines you have there, that should not produce too much recursion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM