我有几个“ newscard” div,它们都可以通过按钮切换。我只需要切换按钮内部的“ newscard”的“ cardexpand”即可。
Ps。这是我在这个网站上的第一个问题,所以请原谅任何不愉快的事情。
<script>
$(document).ready(function(){
$(".cardexpand").hide();
$(".expand").click(function(){
$(this).next(".cardexpand").toggle(1000);
});
});
</script>
<div class="newscard">
<img src="news1.jpg" class="img">
<div class="cardbody">
<p class="cardtitle">James Blyat does not associate with Vainglory players</p>
<p class="carddetails">Mar 29, 2019 • Gaming</p>
<button class="expand">Expand</button>
</div>
<div class="cardexpand">
<hr class="cardhr"></hr>
<p class="cardtext">
Vainglory is just anime of the gaming world and is
for weebs, he says. Vainglory is just anime of the gaming world and is
for weebs, he says.
</p>
</div>
</div>
答案 0 :(得分:0)
id id2 val counter
a red apple 1
a red orange 1
b blue fish 1
c violet beef 1
a yellow banana 2
a black pork 3
函数将不起作用,因为next()
不是您要切换的容器的同级对象。您必须先选择父级。试试这个:
button
答案 1 :(得分:0)