获取当前子元素是其父元素下子元素的排位

4年以前  |  阅读数:313 次  |  编程语言:JavaScript 
const getIndex = el => {
     if (!el) {
         return -1
     }
     let index = 0
     do {
         index++
     } while (el = el.previousElementSibling);
     return index
 }

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8