如果取消注释body.children().each(calc_deep(1));
然后我得到TypeError: Object [object Window] has no method 'attr'
字符串parseInt(deepest.attr('deep'))
,但没有取消注释你可以检查你可以调用的控制台deepest.attr('deep')
。那是什么?
var deepest;
var calc_deep = function(i)
{
$(this).attr('deep',i);
if(i>parseInt(deepest.attr('deep')))
deepest=this;
$(this).children().each(calc_deep(i+1));
}
var find_deepest = function()
{
body=$('body').children().eq(0);
body.attr('deep',0);
deepest=body;
//body.children().each(calc_deep(1));
}
find_deepest();