How to get it? These p's are all sibling elements. How to get the sequence number of one of these p's?
<p</p>//序号0 <p</p>//序号1 <p</p>//序号2 <p</p>//序号3 <p</p>//序号4
function index(el) { return Array.prototype.indexOf.call(el.parentElement.children, el) }
Read in a loop through the prevSiblings of the element, and read a count+1 until no more is read. The final count is the index
Determine how many nodes there are in front of a certain p, and add one for each additional serial number, until there is no node in front, and then the serial number value of the current node is obtained
Read in a loop through the prevSiblings of the element, and read a count+1 until no more is read. The final count is the index
Determine how many nodes there are in front of a certain p, and add one for each additional serial number, until there is no node in front, and then the serial number value of the current node is obtained