我已经能够让我div
的 s 打开并更改图像,但我想要发生的是当我打开一个时另一个关闭,我不知道该怎么做。
我有多个div
这样的。每个id
新闻都有自己的名称:
<div class="article" id="news">
<h2>Hot News: Board Votes to Improve Highways</h2>
<p>As Sporktown’s native and tourist population has increased, so has traffic. The good news is we are taking steps to deal with it. Before traffic becomes too much of a problem we have a plan to expand current highways and improve current ones.</p>
<div class="moreText">
<p>
As part of the new plan, Route 7 will be expanded from a two-way highway to a four-lane highway. This will dramatically speed up North–South travel through that corridor.
</p>
<p>
In addition to the road widening on Route 7, we have finally received approval to for the extension. The original plan called for Route to continue farther North. The project is finally cleared and work has already begun.
</p>
</div>
<img src="img/more-button.png" width="51" height="16" class="changeTextButton">
</div>
这是我到目前为止的jquery脚本:
$(document).ready(function()
{
$('.changeTextButton').click( function()
{
$(this).siblings('.moreText').slideToggle(500);
if ( $(this).attr('src') == 'img/more-button.png')
{
$(this).attr('src', 'img/less-button.png');
}
else
{
$(this).attr('src', 'img/more-button.png');
}
});
});