我有一个脚本,单击时会显示更多信息,再次单击时会隐藏信息。问题是,当单击它时,它会显示和隐藏所有具有相同类名的 div 的信息,而不仅仅是单击的那个。我环顾四周,我认为我需要在其中的某处添加“this”,以便它只影响单击的对象。有人可以解释我做错了什么以及如何达到这种效果吗?
Javascript
<script type="text/javascript">
this$(document).ready(function(){
$(".toggle").click(function(){
$(".hiddenDiv").slideToggle("slow");
});
});
</script>
HTML
<span class="toggle" onClick='return false'>
<h4 class='arrow'>Group Health Insurance</h4>
</span>
<div class='hiddenDiv'>
<p><img src="../images/group.jpg" border="0" alt="Group Insurance" align="left" hspace="5" />Group health insurance coverage is a policy that is purchased by an employer and is offered to eligible employees of the company blah blah blah</p>
</div>
<hr />
<span class="toggle" onClick='return false'>
<h4 class='arrow'>Insurance</h4>
</span>
<div class='hiddenDiv'>
<p><img src="../images/group.jpg" border="0" alt="Group Insurance" align="left" hspace="5" />More info about other types of insurance blah blah blah</p>
</div>
<hr />
提前感谢您的帮助!