采取以下html:
<div class="box">
<a href="javascript:;" onclick="toggle_content(1)">Toggle</a>
<h2>Some Title</h2>
<div class="box_content box_content_1"></div>
<div class="box_content box_content_2"></div>
</div>
<div class="box">
<a href="javascript:;" onclick="toggle_content(1)">Toggle</a>
<h2>Some Title</h2>
<div class="box_content box_content_1"></div>
<div class="box_content box_content_2"></div>
</div>
<script>
function toggle_content(key){
$('.box_content_'+key,$(this).parent()).toggle();
}
</script>
基本上,当单击切换链接时,我希望切换具有匹配类名的同一父级内的元素。上面的代码似乎没有做任何事情。