【发布时间】:2011-02-13 02:42:03
【问题描述】:
我正在使用下面的 javascript (jQuery) 来切换打开两个 DIV。 DIV 可以很好地打开,一次打开一个,这就是我所追求的。但是,我还希望 DIV 在第二次单击时关闭,尽管我尽了最大努力,但还是没有发生!
Javascript:
$(document).ready(function() {
$('.info_tab').click( function() {
var currentID = $(this).next().attr("id");
$('.toggle_info[id!=currentID]').hide(); /* the intention here is to hide anything that is not the current toggling DIV so as to close them as a new one is opened. I thought this would leave the currently selected DIV uninterrupted to toggle closed (below), but it doesn't */
$(this).next().toggle();
return false;
});
});
HTML:
<div class="info_tab">
<h1>Person One</h1><br />
<p>click for less info</p>
</div>
<div id="person_one_info" class="toggle_info">
<p>More information about Philip Grover</p>
</div>
<div class="info_tab">
<h1>Person Two</h1><br />
<p>click for less info</p>
</div>
<div id="person_two_info class="toggle_info">
<p>More information about Roy Lewis</p>
</div>
如果需要更多信息,请提出,我很乐意编辑问题。
干杯,
丰富
【问题讨论】:
标签: javascript jquery html toggle