我定义了一个方法来寻找当前节点的父节点为LI的方法,然后打印出这个节点的类名。

刚开始我写的方法是:

function getLi(src) {
    if(src.nodeName === 'LI')
        return src;
    else
        getLi(src.parentNode);
}

src = getLi(src)

这样的话返回结果一直报错。

后来我才发现我在else中没有返回那个递归的数据。

修改后为

function getLi(src) {
    if(src.nodeName === 'LI')
        return src;
    else
        return getLi(src.parentNode);
}

src = getLi(src)

相关文章:

  • 2022-01-07
  • 2022-12-23
  • 2021-12-23
  • 2022-01-16
  • 2021-08-22
  • 2021-10-16
  • 2021-11-13
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
  • 2021-08-29
  • 2022-01-18
相关资源
相似解决方案