Jquery 在四个列表元素之间循环,应用一个";主动的;班
我想循环四个li元素,它们都包含标记,将适当的类设置为“active”,并删除“active”类。我在想如何通过jQuery实现这一点时遇到了一些困难。 HTML:Jquery 在四个列表元素之间循环,应用一个";主动的;班,jquery,Jquery,我想循环四个li元素,它们都包含标记,将适当的类设置为“active”,并删除“active”类。我在想如何通过jQuery实现这一点时遇到了一些困难。 HTML: 任何帮助都将不胜感激。谢谢。在我看来有点过分了: $('#rightscroll').bind('click', function(e){ var next = $(this).next('li'); if(next){ $('.active').removeClass('active'); next.
任何帮助都将不胜感激。谢谢。在我看来有点过分了:
$('#rightscroll').bind('click', function(e){
var next = $(this).next('li');
if(next){
$('.active').removeClass('active');
next.addClass('active');
}
else{
// maybe select first li element here (index 0)
}
});
对于leftscroll也有同样的逻辑。记住,你必须给一个
li元素在第页的“活动”类就绪
var index = 0;
$("#rightScroll").click(function(){
if(index != 3){
index++;
} else {
index = 0;
}
//this part is untested, it should work though
$("a.active").removeClass("active");
//this is where I am getting hung up
//I need something like...
$.each("li.buttons", function(i){
if(i == index){
$(this).addClass("active");
}
});
});
$("#leftScroll").click(function(){
if(index != 0){
index--;
} else {
index = 3;
}
$.each("li.items", function(i){
if(i == index){
$(this).addClass("active");
}
});
});
$('#rightscroll').bind('click', function(e){
var next = $(this).next('li');
if(next){
$('.active').removeClass('active');
next.addClass('active');
}
else{
// maybe select first li element here (index 0)
}
});