javascript - Click on one li to display the content of the div inside, click on the next li to display the content of the div inside the next li, and hide the content displayed on the previous li. How to write js code?
<ul>
<li >热销榜
<p class="content_item">
<ul >
<li ng-repeat="item in chaoshi">
<p><img src="{{item.img}}" alt=""></p>
<p>{{item.name}}</p>
<p> </p>
<p>
<p style="color: #b9b9b9;">{{item.specifics}}</p>
<p style="color: #ff3800;">¥{{item.price}}</p>
</p>
<p>+</p>
</li>
</ul>
</p>
</li>
<li >牛奶面包
<p class="content_item">
<ul>
<li ng-repeat="item in chaoshi1">
<p><img src="{{item.img}}" alt=""></p>
<p>{{item.name}}</p>
<p> </p>
<p>
<p style="color: #b9b9b9;">{{item.specifics}}</p>
<p style="color: #ff3800;">¥{{item.price}}</p>
</p>
<p>+</p>
</li>
</ul>
</p>
</li>
<li>休闲零食
<p class="content_item">
<ul>
<li ng-repeat="item in chaoshi2">
<p><img src="{{item.img}}" alt=""></p>
<p>{{item.name}}</p>
<p> </p>
<p>
<p style="color: #b9b9b9;">{{item.specifics}}</p>
<p style="color: #ff3800;">¥{{item.price}}</p>
</p>
<p>+</p>
</li>
</ul>
</p>
</li>
</ul>
I don’t know if the questioner uses
JQuery
No, use thesiblings()
method ofJQuery
to select sibling elements.demo