When writing a tab today, you need to use .each() in jquery. Get the number of the li element by getting the index parameter in each() to facilitate the display of the following block. Write it on a test page Ok the following code:
The test results were normal. Later, when I used it on an actual page, I found that when the li list above was changed, the div blocks below did not change with different blocks. I thought it was css style and actual use. Other styles in the page conflicted. After changing all the css selectors to unique ones, I found that the problem still existed, so I judged that it should be here:
There is no problem when taking out the styles in the first and second sentences. In the third sentence, it is normal to add the css style of titsh to the current li tag. That is, the last sentence is to the div obtained through div: eq (index) Failed when adding styles to the block.
So here I am:
I added an alert (index) pop-up window between these two sentences. Looking at the effect, I found that the index values of more than 10 li tags were alerted. When I thought about it, there were actually other li tags on this page. Therefore, the index value iterated by each() does not correspond to the index value of the div block below. In this way, when the li tag above changes, the div block below does not change accordingly, so I changed the js code: