XPath to find elements that does not have an id or class

后端 未结 4 1248
时光取名叫无心
时光取名叫无心 2021-01-30 01:26

How can I get all tr elements without id attribute?

...
...
...

Than

4条回答
  •  没有蜡笔的小新
    2021-01-30 02:10

    if (elm.hasAttribute('id')) { 
    //if id - implement here
        } else if (elm.hasAttribute('class')) { 
            //if class - implement here
        } else { 
            for (i = 1, sib = elm.previousSibling; sib; sib = sib.previousSibling) { 
                if (sib.localName == elm.localName)
                    i++;
            }; 
            segs.unshift(elm.localName.toLowerCase() + '[' + i + ']'); 
        }
    

提交回复
热议问题