div之间的<hr />

时间:2012-01-15 12:59:47

标签: javascript jquery

根据时间我逐个显示div。

我用jquery和

这样做
$("#section_"+index).show();

我的div有如下ID: section_1,section_2,section_3等。

我有var currentSection,它是显示的最后一个的id。 现在我想在显示的最后一个和前一个之间使用hr(水平标尺)。 如果它显示下一个,则应删除旧的hr并显示新的hr。

这可以用jquery完成吗?

2 个答案:

答案 0 :(得分:2)

在CSS中,添加:

.latest {
    border-top: 1px solid #888;
}

在您的JS中,将show语句更改为:

$('.latest').removeClass('latest');
$("#section_"+index).addClass('latest').show();

答案 1 :(得分:0)

techfoobar's answer外,您还可以执行以下操作:

$.fn.showNext = function(selector, delay) {
    var previous = this;
    var next = this.next();

    if (next.length > 0) {
        setTimeout(function() {
            previous.removeClass('latest');
            next.addClass('latest').show().showNext(selector, delay);
        }, delay);
    }
};

$('.section').first().show().showNext('.section', 2000);

这样,您就不需要那些不切实际的section_n索引。演示here on JSFiddle

相关问题