我有下表:
<table>
<tr class="change"><td>Click to change</td></tr>
<tbody id="p1" class="now">
<tr>...</tr>
<tr>...</tr>
<tr>...</tr>
<tr>...</tr>
</tbody>
<tbody id="p2" class="next">
<tr>...</tr>
<tr>...</tr>
<tr>...</tr>
<tr>...</tr>
</tbody>
<tbody id="p3" class="previous">
<tr>...</tr>
<tr>...</tr>
<tr>...</tr>
<tr>...</tr>
</tbody>
</table>
我想用“现在”类隐藏tbody,当我点击更改行时,显示带有“next”类的那个。
我的Jquery(仅在现在和下一次计算):
$(document).ready(function(){
$('.change').click(function(){
$('.now').hide('slow', function(){
$('.next').show('slow', function(){
$('#p1').removeClass('recent');
$('#p2').removeClass('next');
$('#p1').addClass('next');
$('#p2').addClass('recent');
});
});
});
});
我看到我做错了所以我想问你,如何以某种方式很好地同步它,当我点击“更改”时我的“现在”tbody变为“previous”,“next”变为“现在”和“上一个”成为下一个?
答案 0 :(得分:3)
试
$(document).ready(function () {
$('.change').click(function () {
$('.now').hide('slow', function () {
$('.next').show('slow', function () {
$prev = $('.previous');
$now = $('.now');
$next = $('.next');
$prev.removeClass('previous').addClass('next');
$now.removeClass('now').addClass('previous');
$next.removeClass('next').addClass('now');
});
});
});
});
答案 1 :(得分:1)
$('.change').click(function(){
var now = $('.now');
var next = $('.next');
var previous = $('.previous');
now.hide('slow', function(){
next.show('slow');
previous.removeClass('previous').addClass('next');
now.removeClass('now').addClass('previous');
next.removeClass('next').addClass('now');
});
});
答案 2 :(得分:-1)
$('.change').click(function() {
$('.now').attr('class', 'previous');
$('.next').attr('class', 'now');
$('.previous').attr('class', 'next');
});