1
我试图制作一个jQuery插件,它将采用一个正方形,在其中放置三个方块,然后在这三个方块内放置三个更小的正方形。我并不需要或想要完整的代码,因为这是我自己的问题搞清楚,但我无法弄清楚如何使一个jQuery插件调用本身,如:如何制作递归jQuery函数?
(function($){
$.fn.squares = function(type) {
var recursionDepth = 1;
return this.each(function() {
var $this = $(this);
if (++ recursionDepth > 3) {console.log('rec lim');return;}
// put div.squares in $this
$('.square', $this).squares();
});
};
})(jQuery);