-2

我已经发现了这个威胁:How to toggle only the *next* .class or div (not the rest)

但是,如果我要切换的类不是点击元素的子元素,我必须做什么,例如:

<span onclick="$(this).next('.showme').slideToggle();">Klick to show first Showme-Class</span>
<div class="showme">You've clicked the first span-element</div>

<span onclick="$(this).next('.showme').slideToggle();">Klick to show second Showme-Class</span>
<div class="showme">You've clicked the second span-element</div>

<span onclick="$(this).next('.showme').slideToggle();">Klick to show third Showme-Class</span>
<div class="showme">You've clicked the third span-element</div>

更具体:在这个例子中......

<div class="myclickclass">
<span onclick="this().next('.showme').slideToggle(100);">Click me</span>
<div class="showme">You've clicked</div>
</div>

“showme”类是“myclickclass”类的一部分(内部)...... jQuery 为我工作。

<div class="myclickclass">
<span onclick="this().next('.showme').slideToggle(100);">Click me</span>
</div>
<div class="showme">You've clicked</div>

在这个例子中,“showme”类不是我的“myclickclass”类的一部分。jQuery 对我不起作用。

4

1 回答 1

2
$(this).parent().next('.showme')

如果它不在里面。

于 2013-11-13T10:52:12.247 回答