这是我的代码:
<div class='silderitem'>
Some Content
</div>
<div class='silderitem'>
Another Some Content
</div>
<div class='silderitem'>
Again Another Some Content
</div>
<a class="next">next</a>
当我使用jquery单击“next”时,我想更改下一个类。我尝试过这个,但它不起作用。
<script>
$(document).ready(function(){
var Slideshow=$('.slideritem');
$(".next").click(function(){slideshow.next();return false});
</script>
有人可以告诉我解决方案吗?
答案 0 :(得分:1)
如果你想循环浏览项目,隐藏那些未选中的项目,这样的事情可能会有效:jsfiddle
的CSS:
.silderitem { display: none }
.next { cursor: pointer }
jquery的:
$('.selected').show();
$(".next").click(function(){
var selected = $('.selected');
selected.removeClass('selected');
selected.hide();
var next = selected.next(".silderitem");
if(next.length === 0) {
next = $(".silderitem").first();
}
next.addClass('selected');
next.show();
});
HTML:
<div class='silderitem selected'>
Some Content
</div>
<div class='silderitem'>
Another Some Content
</div>
<div class='silderitem'>
Again Another Some Content
</div>
<a class="next">next</a>