我真的是 jQuery 的新手,我正处于一场小危机中。
$(document).ready(function(){
$(".help_box").click(function(){
$(".help_box_answer").toggle(400);
});
});
这是 HTML 本身
<div class="help_box">
<div class="help_box_title">title box</div>
<div class="help_box_answer">
<p>Hidden message</p>
</div>
</div>
class="help_box_answer"
设置为 display:none
当我点击 div 时,会发生这种情况
最佳答案
使用 this
只引用您点击的元素,而不是所有具有相同类的 div:
$(document).ready(function(){
$(".help_box").click(function(){
$(this).find(".help_box_answer").toggle(400);
});
});
关于javascript - 单击打开所有 div 而不是一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38488799/