我有两个div:
<a href="#" class="component_expand"></a>
<div class="component_wrapper">
</div>
<a href="#" class="component_expand"></a>
<div class="component_wrapper">
</div>
Jquery代码:
<script type="text/javascript">
$(document).ready(function(){
$(".component_wrapper").hide();
$(".component_expand").show();
$('.component_expand').click(function(){
$(".component_wrapper").slideToggle();
});
});
</script>
我每次点击“组件展开”时都会尝试打开一个DIV。现在打开两个 我很高兴他们帮助我的人
答案 0 :(得分:1)
您需要使您的选择器具体,请使用next。
$(this).next().slideToggle();
尝试:
$(document).ready(function(){
$(".component_wrapper").hide(); //You can do this using css rule itself
$(".component_expand").show().click(function(){
$(this).next().slideToggle();
});
});
<强> Demo 强>
答案 1 :(得分:1)
使用this
和.next
$('.component_expand').click(function(){
$(this).next(".component_wrapper").slideToggle();
});