我的HTML代码如
<div id="thumbs" class="content mThumbnailScroller">
<ul>
<li><img src="images/ind_thumb.jpg" alt="1st image description" /></li>
<li><img src="images/pak_thumb.jpg" alt="2nd image description" /></li>
<li><img src="images/thi_thumb.jpg" alt="3rd image description" /></li>
<li><img src="images/maye_thumb.jpg" alt="4th image description" /></li>
<li><img src="images/singa_thumb.jpg" alt="5th image description" /></li>
<li><img src="images/keniya_thumb.jpg" alt="6th image description" /></li>
<li><img src="images/aus_thumb.jpg" alt="7th image description" /></li>
<li><img src="images/uae_thumb.jpg" alt="8th image description" /></li>
<li><img src="images/wi_thumb.jpg" alt="9th image description" /></li>
<li><img src="images/zim_thumb.jpg" alt="10th image description" /></li>
<li><img src="images/sa_thumb.jpg" alt="11th image description" /></li>
<li><img src="images/sl_thumb.jpg" alt="12th image description" /></li>
</ul>
</div>
如何从上面的代码中获取下一张图像的src。
答案 0 :(得分:0)
我认为你需要像这样检查一下。
$( "li" ).click(function() {
var current=$('li img').attr('src').split('/')[1].split('_')[0];
alert(current);
$('li img').attr('src','images/'+(++current)+'_thumb.jpg');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="thumbs" class="content mThumbnailScroller">
<ul>
<li><img src="images/1_thumb.jpg" alt="1st image description" /></li>
</ul>
</div>