我正在运行一些jQuery来添加/删除当前的类。它适用于兄弟姐妹,但不适合兄弟姐妹的孩子。有人有什么好主意吗?
$('#rotator_buttons td').click(function(){
if($(this).hasClass('current')) {
$(this).removeClass('current');
}
else {
$(this).addClass('current').siblings().removeClass('current');
$(this).siblings().children('a').removeClass('current');
$(this).children('a').addClass('current');
}
return false;
});
HTML
<table id="rotator_buttons">
<tbody>
<tr>
<td id="pause-play"><a href="#"><!-- --></a></td>
<td><a href="#" id="1" target="_self" onclick="javascript:increment_slideshow(0)">Button 1</a></td>
<td><a href="#" id="2" target="_self" onclick="javascript:increment_slideshow(0)">Button 2</a></td>
<td><a href="#" id="3" target="_self" onclick="javascript:increment_slideshow(0)">Button 3</a></td>
<td><a href="#" id="4" target="_self" onclick="javascript:increment_slideshow(0)">Button 4</a></td>
</tr>
答案 0 :(得分:0)
$('#rotator_buttons td').click(function(){
if($(this).hasClass('current')) {
$(this).removeClass('current');
}
else {
$(this).children('a').addClass('current');
$(this).siblings().each(function(){
$(this).removeClass('current');
$(this).children('a').removeClass('current');
});
}
return false;
});